4

Is there a way to save some settings to the local computer that is not cookies with a user script?

It is difficult to make a user script that is for multiple domains if the settings are not global.

From a comment: "I am using scriptish ".

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
John
  • 5,942
  • 3
  • 42
  • 79
  • Clarify. You want to have settings that apply across multiple domains? Is it OK if the settings are kept in a hand-edited file, or must the script be able to set them? – Brock Adams Feb 25 '12 at 21:09

1 Answers1

13

Absolutely, it's very easy. The Greasemonkey wiki documents four methods that allow you to deal with saving values, which can be settings or anything else you want to store:

You might want to check out the main API page for other useful methods, and there's also a complete metadata block documentation page.

The only way this might not work is in a Google Chrome Content Script. There are a few solutions though: you can either use the Google Chrome GM_* userscript in addition to yours, or you can make the GM_setValue and GM_getValue methods available by including this at the beginning of your user script (from Devine.me):

if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) {
    this.GM_getValue=function (key,def) {
        return localStorage[key] || def;
    };
    this.GM_setValue=function (key,value) {
        return localStorage[key]=value;
    };
    this.GM_deleteValue=function (key) {
        return delete localStorage[key];
    };
}
BenjaminRH
  • 11,974
  • 7
  • 49
  • 76
  • 1
    does the second function really needs to return something ? It seems that only `localStorage[key]=value;` without return before would work. – Sergio Abreu Mar 17 '14 at 14:17