Tampermonkey Config

Simple Tampermonkey script config library

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

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

作者
PRO-2684
版本
0.2.2
建立日期
2023-07-05
更新日期
2023-07-06
尺寸
2.8 KB
授權條款
GPL-3.0

🪄 Function

Simple config lib for Tampermonkey scripts.

🤔 Permission

This script needs the following permissions to work:

// @grant        GM_setValue // Save your config
// @grant        GM_getValue // Get your config
// @grant        GM_registerMenuCommand // Register menu
// @grant        GM_unregisterMenuCommand // Update menu

📖 Usage

let config_desc = { // Config description
    password: {
        name: "Password", // Display name
        value: "tmp", // Default value
        processor: (v) => { // Process user inputs, throw error if invalid
            if (v.length < 3) throw "Too short!";
            return v;
        }
    },
    enabled: {
        name: "Enabled",
        value: true,
        processor: GM_config_builtin_processors.boolean // You can use builtin processors
    },
    price: {
        name: "Price",
        value: 10,
        processor: GM_config_builtin_processors.integer(0, 100) // Some builtin processors accept arguments
    },
    foo: {
        name: "Foo",
        value: "bar"
        // You may omit processor if you don't need to validate or process user inputs
    }
}

let config = GM_config(config_desc); // Register menu commands
console.log(config.price); // Start using config as you wish 🎉

⚠️ Note

  • This project is in early development.
  • Avoid modify config values in your script. If you really need to do so, remember to invoke _GM_config_register(config_desc, config); so as to update the displayed menu.

QingJ © 2025

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