I would like to add a remove/blacklist button next to all links in the Blogspot statistics. Some of them are referrer spam, and I would like to remove them forever. So far I'm selecting them using this kind of jQuery selector:


but I would like it to be more flexible, because I have to manually edit the script for each new domain.


To store data for later reuse, you would use the GM_setValue function as well as GM_getValue().
These two functions have the unique advantage that they store data across multiple domains. Now that globalStorage is obsolete, they are the only method to do that.

Or you could also use localStorage or cookies, but these may not allow for what you want because they only work for one domain at a time.

If you try GM_setValue(), you'll probably need to do it by using the GM_SuperValue utilities instead, since GM_setValue(), by itself, does not do a good job of storing anything but strings.

However, in this particular case, adding a line to the script for each site might be better because:

  1. If your example is typical, it is only one new line per site (not counting any site-specific @include directives).
  2. You need to store code as well as data.
    For example, in the question, you are using not only the selector ('a[href*="referer.spam.domain"]'), but also the relationship (.closest("li")). Both of these would presumably have to be stored.
    Storing this is a new level of complexity that is probably not warranted in this case.
  3. It's not as simple as just "storing data". You will also need ways to: Add, List, Edit and Delete values. That's a lot more code if you want to do it right. But you can use utilities like "Script Options Dialog" to help with the user interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.