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.

So how do you still run the program this way? Screenshot

Author: Хлеб, 2019-08-03

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:

step 1

2) Then run the script from the context menu of the page:

step 2

3) Then you will see the Tampermonkey menu item, which you can run:

step 3

 1
Author: Brock Adams, 2019-08-03 15:48:40