sfarbota
sfarbota

Reputation: 2637

Using Greasemonkey, is it possible to make some parts of the script apply to certain sites and other parts apply to different sites?

The reason I want to do this is that I'm writing a script for meebo.com that involves changing the background and replacing some pictures with css. I'd like to add links to it from other sites (namely Gmail, Google Calendar, etc.) Is it possible to accomplish this with one Greasemonkey script? (I think this is a general enough question to exclude my actual code but if it would help, just leave a comment saying so.)

Upvotes: 0

Views: 124

Answers (1)

npdoty
npdoty

Reputation: 4757

Well, I think the conventional method would be to write two scripts, one that only @include's meebo.com (and changes the background image) and another that @include's http://* or whatever set of other URLs (and adds a link to meebo).

But if you're set on writing only a single script, you could use a series of if statements to accomplish the same effect. That would look something like this:

// @include        http://*
// ==/UserScript==
if (window.location.hostname.match(/meebo\.com/) {
    //change background images and do other meebo.com specific actions
} else if (window.location.hostname.match(/google\.com/) {
    //add a link to the DOM (or some other Google specific action)
}

Upvotes: 2

Related Questions