tampermonkey running the script via the context menu
How do I run a script by right-clicking and selecting the desired script? Using this parameter:
@ run-at context-menu
And tried to use this function:
GM_registerMenuCommand ("Запуск", start);
Where start is the name of the function that starts the program.
1 answers
I apologize for my machine-Russian translation.
In any case, @run-at context-menu
andGM_registerMenuCommand()
are not specifically intended to be shared.
The first one places the context menu item on each page. Second place - menu menu Tampermonkey only for selected pages (as defined by directives @ match
,@ include
etc.).
Consider this Tampermonkey script (which only works in Chrome browsers):
// ==UserScript==
// @name context-menu fun (забавное контекстное меню)
// @match https://ru.stackoverflow.com/tour
// @grant GM_registerMenuCommand
// @run-at context-menu
// ==/UserScript==
console.log ("Запуск скрипта");
GM_registerMenuCommand ("Запуск", start);
function start () {
console.log ("Функция запуска запущена.");
}
Please note that the string @match
will be ignored because @run-at context-menu
is used.
If you install this script and visit https://ru.stackoverflow.com/tour, you will see:
1) First, there is no Tampermonkey menu item for this script and no messages in the console:
2) Then run the script from the context menu of the page:
3) Then you will see the Tampermonkey menu item, which you can run: