Search code examples
greasemonkeyscriptish

Script to save settings


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 ".


Solution

  • 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];
        };
    }