Tampermonkey 配置

简易的 Tampermonkey 脚本配置库

当前为 2023-07-06 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @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

🪄 功能

简易的 Tampermonkey 脚本配置库。

🤔 权限

这个脚本需要以下权限:

// @grant        GM_setValue // 保存配置
// @grant        GM_getValue // 获取配置
// @grant        GM_registerMenuCommand // 注册(不可用)菜单
// @grant        GM_unregisterMenuCommand // 更新菜单

📖 使用

let config_desc = { // 配置描述
    password: {
        name: "Password", // 显示名称
        value: "tmp", // 默认值
        processor: (v) => { // 处理用户输入,若不合法则报错
            if (v.length < 3) throw "Too short!";
            return v;
        }
    },
    enabled: {
        name: "Enabled",
        value: true,
        processor: GM_config_builtin_processors.boolean // 你可以使用内置处理器
    },
    price: {
        name: "Price",
        value: 10,
        processor: GM_config_builtin_processors.integer(0, 100) // 部分内置处理器需要参数
    },
    foo: {
        name: "Foo",
        value: "bar"
        // 若你认为不需要验证或处理用户输入,你也可以忽略 processor 项
    }
}

let config = GM_config(config_desc); // 注册(不可用)菜单命令
console.log(config.price); // 可以开始使用了 🎉

⚠️ 注意

  • 这个项目正处于早期发展阶段
  • 尽量避免在你的脚本里修改配置。若你确实需要这么做,记得调用 _GM_config_register(config_desc, config); 以便更新展示的菜单

QingJ © 2025

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