Table of Contents Previous entry (api:GM_openInTab) Next entry (api:GM_setClipboard)
GM_registerMenuCommand allows userscripts to add a new entry to the userscript's menu in the browser, and specify a function to be called when the menu item is selected.
Menu items created from different frames are merged into a single menu entry if name, title and accessKey are the same.
The function takes three parameters:
options or accessKey can be specified.GM_registerMenuCommand call. If specified, the according menu item will be updated with the new options. If not specified or the menu item can't be found, a new menu item will be created.chrome://extensions/shortcuts in Chrome, about:addons + "Manage Extension Shortcuts" in Firefox)true. Please note that this setting has no effect on the menu command section that is added to the page's context menu.The function return a menu entry ID that can be used to unregister the command.
Here is an example of how the function might be used:
const menu_command_id_1 = GM_registerMenuCommand("Show Alert", function(event: MouseEvent | KeyboardEvent) {
alert("Menu item selected");
}, {
accessKey: "a",
autoClose: true
});
const menu_command_id_2 = GM_registerMenuCommand("Log", function(event: MouseEvent | KeyboardEvent) {
console.log("Menu item selected");
}, "l");
GM_unregisterMenuCommand removes an existing entry from the userscript's menu in the browser.
The function takes a single parameter, which is the ID of the menu item to remove. It does not return a value.
Here is an example of how the function might be used:
const menu_command_id = GM_registerMenuCommand(...);
GM_unregisterMenuCommand(menu_command_id);