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:
- If your example is typical, it is only one new line per site (not counting any site-specific
- 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.
- 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.