Config_Manager

设置获取配置的APIs

当前为 2023-10-02 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/476522/1258967/Config_Manager.js

  1. // ==UserScript==
  2. // @name Config_Manager
  3. // @namespace Violentmonkey Scripts
  4. // @grant GM_getValue
  5. // @grant GM_setValue
  6. // @grant GM_addValueChangeListener
  7. // @grant GM_registerMenuCommand
  8. // @grant GM_unregisterMenuCommand
  9. // @author axototl
  10. // @description 设置获取配置的APIs
  11. // ==/UserScript==
  12. 'use strict';
  13.  
  14. let config = {};
  15. let register;
  16.  
  17. (() => {
  18. // const _APIs = ["GM_getValue", "GM_setValue", "GM_addValueChangeListener", "GM_registerMenuCommand", "GM_unregisterMenuCommand"];
  19. // for (const val in _APIs)
  20. // if (!(val in globalThis)) throw new Error("需要API权限!!!");
  21. const boolean_prefix = ["❌(已禁用)", "✅(已启用)"];
  22. config = {};
  23. register = ({name, type = "other", prompts, input: func = prompt, callback: listener = Function.prototype}) => {
  24. let val = GM_getValue(name);
  25. config[name] = val;
  26. if (type === 'bool') {
  27. let cont;
  28. const reg = () => cont = GM_registerMenuCommand(boolean_prefix[val | 0] + prompts, () => GM_setValue(name, !val));
  29. GM_addValueChangeListener(name, (_1, ov, newval) => {
  30. config[name] = val = newval;
  31. GM_unregisterMenuCommand(cont);
  32. reg();
  33. listener(name, ov, newval, cont);
  34. });
  35. reg();
  36. } else if (type === "other") {
  37. const cont = GM_registerMenuCommand(prompts, () => GM_setValue(name, func()));
  38. GM_addValueChangeListener(name, (_1, ov, newval) => (config[name] = newval, listener(name, ov, newval, cont)));
  39. }
  40. console.debug(type, name, "\nRegistered!");
  41. };
  42. })();

QingJ © 2025

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