QuickMenu

油猴菜单库,支持开关菜单,支持状态保持,支持 Iframe

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greatest.deepsurf.us/scripts/496315/1392531/QuickMenu.js

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Autore
JiyuShao
Versione
2024-06-11
Creato il
28/05/2024
Aggiornato il
11/06/2024
Dimensione
8,01 KB
Licenza
Non disponibile

QuickMenu

油猴菜单库,支持开关菜单,支持状态保持,支持 Iframe

API 定义

QuickMenu.add

Key 类型 必填 参数描述
name string 菜单名称
type 'button' 或 'toggle' 菜单类型,toggle 会额外展示当前菜单状态
shouldInitRun boolean 或 () => boolean 注册菜单后是否要立即执行回调,默认为 false
shouldAddMenu boolean 或 () => boolean 当前环境是否注册菜单,默认为 true
callback (value: undefined 或 'on' 或 'off' ) => void 初始化执行和点击菜单的回调函数,如果是 toggle 类型的话 value 会返回点击后状态(onoff

使用示例

QuickMenu.add({
  // 菜单名称
  name: '开启 eval 调试',
  // 菜单类型
  type: 'toggle',
  // 开启初始化执行回调,这样宿主和 Iframe 环境会初始化执行
  shouldInitRun: true,
  // 这里只有最顶层宿主才会注册菜单,点击 toggle 之后也会发送消息给其他环境,同步执行回调
  shouldAddMenu: () => {
    return unsafeWindow === unsafeWindow.top;
  },
  // 执行回调逻辑
  callback: (value) => {
    // 保存原始的 eval 函数
    const originalEval = eval.originalEval ? eval.originalEval : eval;
    eval.originalEval = originalEval;
    if (value === 'on') {
      // 定义一个新的 eval 函数
      const patchedEval = function (code) {
        // 在 eval 的代码前插入 debugger 语句
        const codeWithDebugger = `debugger; ${code}`;
        return originalEval(codeWithDebugger);
      };
      patchedEval.prototype = originalEval.prototype;
      // 替换全局的 eval 函数
      unsafeWindow.eval = patchedEval;
    } else if (value === 'off') {
      unsafeWindow.eval = originalEval;
    }
  },
});