Greasemonkey: Reconsider implementing GM_registerMenuCommand in GM 4.x

Created on 20 Nov 2017  ·  5Comments  ·  Source: greasemonkey/greasemonkey

As I saw (see comment) GM_registerMenuCommand is replaced with HTML5 context menu. and there's no plan to add it in GM 4.x.

Nevertheless, I've started this separate issue. in hope that you'll might reconsider.


I understand that adding some context menu options in the native context menu,
is useful for those that do want to add more entries in that.
Such as this new test script by arantius search-with-google.
screenshots:
2017-11-20_171908 2017-11-20_172014


But, for userscripts that use GM_registerMenuCommand only for settings, i.e. you only configure then only once in a while.
and apply to all pages,
such as the popular:
Mouseover Popup Image Viewer, (settings screenshot)
YouTube Link Title (settings screenshot) and
Linkify Plus Plus (settings screenshot )

Imagine having installed these scripts that create a total of 3 entries on top of the context menu
that are not needed most of the time:
it would make use the context menu on the page cluttered and unpractical.

And then the script author, in order to avoid cluttering the context menu just for the sake for offering settings,
he would either register a keyboard shortcut on every page (with no UI?)
or create a new dedicated button element on every page.


So, I'd like to ask you please to reconsider implementing GM_registerMenuCommand inside the toolbar button popup, similar to how it was in GM 3.x, as well as in the other most used scripts managers available, Tampermonkey and Violentmonkey.
,
It would appear between/below the "Greasemonkey is active/disabled" entry,
and above the 'User scripts for this tab' list (GM 4.1 beta4).

Most helpful comment

All 5 comments

For reference, I quote the relevant discussion from https://github.com/greasemonkey/greasemonkey/issues/2559 :


(eight04)

_arantius I saw that GM_registerMenuCommand is replaced with HTML5 context menu. Is there any plan to add it in GM 4.x? I can't find the tracking issue._

(arantius)

_No. Greasemonkey's policy has been (for a long time) not to implement "user space" features. Any script can do this, or @require something like this polyfill which does it. Greasemonkey doesn't need to build nor support this feature to enable scripts to use it. The point here is just to do what the polyfill does: make it easier to update scripts to be compatible with both old and new versions of Greasemonkey._

(eight04)

_I meant if GM4 will also provide an API to execute script commands from the UI of userscript manager like old GM_registerMenuCommand, not asking whether there will be a HTML5 contextmenu API in GM. GM_registerMenuCommand is often used to launch script configuration dialog, which shouldn't be polyfilled as a HTML5 contextmenu IMHO._

_BTW, I have created a library to work with HTML contextmenu just few months ago, which would reuse contextmenu property on the page if it is already set:_
_https://github.com/eight04/GM_context_

(arantius)

_GM_registerMenuCommand is often used to launch script configuration dialog, which shouldn't be polyfilled as a HTML5 contextmenu IMHO_

_Why not?_

(eight04)

_Why not?_

_1. The command on the contextmenu should be:_

_- An action which works on specified context (element). For example, when some text is selected, "Copy" command, which is an action to work with the selection, is shown._
_- A shortcut to execute specified command for convenience._
_A "My userscript setting" command doesn't fall into both categories. It does not depend on the context, also there is no need to use a shortcut for configuration._

_2, It is not reliable. It may be blocked/replaced by page scripts._

(trlkly)

_I agree with the conceptual level difficulties. I do not have any extensions anymore that use the context menu for settings. It would get pretty busy pretty quickly if they did, since I run a lot of extensions._

_But the main reason I see is that Chrome has removed the HTML5 context menu from the spec, which means it's probably going to be removed from Firefox, too. I didn't even know it existed, seeing as I've not seen any site use it. Apps just spin their own, blocking the real context menu (which is a huge, huge annoyance in most cases. That removes functionality.)_

This gives me a headache trying to think about how the scripts would interact. Assuming there was a menu option and said menu option opened some sort of window / box / dialog / whatever to change settings, is that newly generated window considered to be in the 'content script' context and therefore able to send messages to the extension? And if it's not then how does one send a message back to the content script, so that settings can be changed?


Though, it seems that a common theme is settings menus. I'd be in favor of having staticly defined configuration fields in the metablock that are then generated and can be saved / modified through the Monkey menu. Similar to a resource but are changed by going Monkey Menu -> Script -> Config -> Items.

_I'd be in favor of having staticly defined configuration fields in the metablock that are then generated and can be saved / modified through the Monkey menu. Similar to a resource but are changed by going Monkey Menu -> Script -> Config -> Items._

I'm afraid that using static configuration fields in the metablock would make it too limiting:
for example, for the 1st mentioned script Mouseover Popup Image Viewer,
apart from the current practical layout(dropdown menus, checkboxes, textboxes with scrollbar, textarea),
the settings menu currently offers:

  • import/export the settings (to clipboard),
  • install rules from the MPIV repository right inside the settings,
  • there's find-as-you-type rules when there are a lot of custom host rules installed,
  • it validates whether the entered custom host rule is valid JSON, and highlights the input row red if not,

Plus, its author should have to rewrite the entire 'setup code.

settings screenshot

@legnaleurc Gosh, that could be an issue for some people. As a total layman, I have no idea, but do you happen to know of an alternative way to add context menu items, to replace the method that uses

? Is there some simple method I am not aware of that's usable from a userscript?

Was this page helpful?
0 / 5 - 0 ratings