Config_Getter

设置获取配置的APIs

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

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

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

QingJ © 2025

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