GM_createMenu

油猴菜单库,支持开关菜单,支持批量添加,为您解决批量添加和开关菜单的烦恼

Verze ze dne 22. 09. 2020. Zobrazit nejnovější verzi.

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://updategf.qytechs.cn/scripts/411512/850359/GM_createMenu.js

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

Autor
wish king
Verze
0.1.6
Vytvořeno
18. 09. 2020
Aktualizováno
22. 09. 2020
Size
6,7 KB
Licence
neuvedeno

当你写油猴插件的时候,突然发现需要一个开关按钮或批量创建菜单,怎么办?
调用底层API自己实现?
未必太麻烦了,而且删除菜单后,新菜单会上下调换位置,变得你心都乱了。
总之慢慢采坑吧。
嗯,好了,今天封装了一个开关菜单库,它完美解决了批量添加开关菜单的烦恼。
OK,愉快的开始使用吧!

脚本引用:
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_setValue //如果要记忆菜单开关状态,需要开启
// @grant GM_getValue //如果要记忆菜单开关状态,需要开启
// @require https://greasyfork.org/scripts/411512-gm-createmenu/code/GM_createMenu.js?version=850355

代码调用:

GM_createMenu.add([
    //开关菜单
    {
        on : {
            name : "开启",
            callback : function(){
                alert("我开启了");
            }
        },
        off : {
            name : "关闭",
            callback : function(){
                alert("我关闭了");
            }
        }
    },
    //开关菜单
    {
        load : function(){
            alert("loaded");
        },
        on : {
            name : "进入编辑模式",
            accessKey: 'E',
            callback : function(){
                alert("我已进入编辑模式");
            }
        },
        off : {
            name : "退出编辑模式",
            accessKey: 'X',
            callback : function(){
                alert("我已退出编辑模式");
            }
        }
    },
    //普通菜单
    {
        name : "test1111",
        callback : function(){
            alert("test11111");
        }
    },
    {
        name : "test2222",
        callback : function(){
            alert("test2222");
        },
        load : function(){
            alert("loaded1111");
        }
    }
]);
//GM_createMenu.storage=true;
GM_createMenu.create({storage:true});

或

GM_createMenu.add({
    on : {
        default : true,
        name : "Open",
        callback : function(){
            alert("I'm Open.");
        }
    },
    off : {
        name : "Close",
        callback : function(){
            alert("I'm Close.");
        }
    }
});
GM_createMenu.add({
    on : {
        name : "Edit",
        accessKey: 'E',
        callback : function(){
            alert("I am editing");
        }
    },
    off : {
        default : true,
        name : "Exit Edit",
        accessKey: 'X',
        callback : function(){
            alert("I'm exit.");
        }
    }
});
GM_createMenu.create();