Tampermonkey Config

Simple Tampermonkey script config library

Versione datata 05/07/2023. Vedi la nuova versione l'ultima versione.

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/470224/1215817/Tampermonkey%20Config.js

Autore
PRO-2684
Versione
0.1.0
Creato il
05/07/2023
Aggiornato il
05/07/2023
Licenza
GPL-3.0

🪄 Function

Simple config lib for Tampermonkey scripts.

📖 Usage

let default_values = { // Default config values
    "foo": "bar",
    "aaa": "true"
};
let handler = wrapper((name, value) => { // You can validate user input here...
    switch (name) {
        case "foo":
            return value === "bar";
        case "aaa":
            return value === "true" || value === "false";
        default:
            return true;
    }
});
let config = new Proxy(default_values, handler);
register(config); // Register the config so that it shows up on Tampermonkey menu

After this, you may use config.foo and config.aaa to get config values.

⚠️ Note

  • Only string values are expected due to the use of prompt() as user input.
  • Avoid modify config values in your script, because if you try to set an invalid value, alert() will be invoked. (Although it will work)