GM_createMenu

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

بۇ قوليازمىنى بىۋاسىتە قاچىلاشقا بولمايدۇ. بۇ باشقا قوليازمىلارنىڭ ئىشلىتىشى ئۈچۈن تەمىنلەنگەن ئامبار بولۇپ، ئىشلىتىش ئۈچۈن مېتا كۆرسەتمىسىگە قىستۇرىدىغان كود: // @require https://update.greasyfork.org/scripts/411512/864854/GM_createMenu.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

ئاپتورى
wish king
نەشرى
0.1.10
قۇرۇلغان ۋاقتى
2020-09-18
يېڭىلانغان ۋاقتى
2020-11-01
Size
6.9 KB
ئىجازەتنامىسى
يوق

当你写油猴插件的时候,突然发现需要一个开关按钮或批量创建菜单,怎么办?
调用底层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=851631

代码调用:

GM_createMenu.add([
    //开关菜单
    {
        on : {
            name : "开启",
            callback : function(){
                alert("我开启了");
            }
        },
        off : {
            name : "关闭",
            callback : function(){
                alert("我关闭了");
            }
        }
    },
    //开关菜单
    {
        load : function(menuStatus){
            if(menuStatus==="on") 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();