Config_Getter

设置获取配置的APIs

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

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

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

QingJ © 2025

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