Greasy Fork

Greasy Fork is available in English.

GMX_menu

A simple userscript menu manager, treats all menu items as a GMX_menu object.

当前为 2023-08-24 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/473817/1240188/GMX_menu.js

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

作者
DianaBlessU
版本
0.1
创建于
2023-08-24
更新于
2023-08-24
大小
2.8 KB
许可证
暂无

/*

A simple userscript menu manager, Treats all menu items as a menu object.

Key Features:

1. Create and access menu items via GMX_menu object, no need to care the item order.
2. Caption text of menu item can be changed at any time.
3. Menu item can act as a Check box.
4. Menu items can act as a radio button group.


Usage:

// To use this script, you need to grant GM_registerMenuCommand and GM_unregisterMenuCommand.

// Install a new menu, (all previous menu items will be removed)

// The value of name must be unique in the menu.
// If autoRefresh is true, when the menu item is modified, the rerendering will be automatically executed,
// otherwise its appearance will remain unchanged unless you manually call the GMX_menu.refresh() method.
// If a menu item has a checked attribute, it will be rendered as a checkable entry.
// If it also has a group attribute at the same time, it will be associated to a radio button group.

const sampleOptions = {
autoRefresh: true,
items: [
{name: "cmd1", text: "🥣 Radio 1", checked: true, group: "g1", callback: ()=>{alert("Radio 1 clicked!")}},
{name: "cmd2", text: "⭐ Radio 2", checked: false, group: "g1", callback: ()=>{alert("Radio 2 clicked!")}},
{name: "sep1", separator: true},
{name: "cmd3", text: "🍬 Checkbox 3", checked: false, callback: ()=>{alert("Checkbox 3 clicked!")}},
{name: "cmd4", text: "🍦 Cammand 4", callback: ()=>{alert("Cammand 4 clicked!")}},
]
}
GMX_menu.install(sampleOptions);

// Remove menu.
GMX_menu.uninstall()

// Change the caption text of a menu item by name.
GMX_menu.setText(name, text)

// Get the check state of a menu item by name.
// If the item is unchackable, it will returns undefined.
GMX_menu.isChecked(name)

// Trigger the select event of specific menu item by name.
// The check state of the item will also be changed if it's checkable.
GMX_menu.triggerSelect(name)

// Select the specific item on userscript menu without excuting it's callback function.
// Usually used to modify the check state of a specific menu item.
GMX_menu.renderSelect(name)

// Rebuild the whole menu by installed option.
GMX_menu.refresh()

*/