Tampermonkey Config

Simple Tampermonkey script config library

目前為 2023-07-05 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/470224/1215817/Tampermonkey%20Config.js

作者
PRO-2684
版本
0.1.0
建立日期
2023-07-05
更新日期
2023-07-05
尺寸
2.1 KB
授權條款
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)

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址