Execute script automatically AND display context menu

Post Reply
kriegaex
Posts: 4
Joined: 16.05.13 09:26:05
Contact:

Execute script automatically AND display context menu

Post by kriegaex » 06.04.18 10:19:40

I have a script which highlights quoted e-mails in replies via mark.js. It runs automatically at whatever the standard time/trigger is (no @run-at statements in the script), which works perfectly for my own e-mail provider's web interface.

Now I was curious if the script would also work for more AJAX-ish sites such as Gmail or others. It does not, probably because Gmail runs so many asynchronous things in so many frames that somehow the e-mail content is not yet there when the script executes. When I switch the script to display a context menu and I select it from there, it perfectly highlights my quoted e-mails on Gmail too, though. So this is a timing problem. I am a Java back-end guy, not a JS front-end type. I have no clue how to solve this. OTOH, I rarely use Gmail. So it would be okay if the script ran automatically for my own provider but on demand on Gmail. Is there a way to enable both in parallel, i.e. have the script run automatically but also additionally to display it in the context menu? Then I could at least make it run on other sites, too. BTW, no, I do not want to copy the script and have to maintain two versions of it for different sites.
--
Alexander Kriegisch
https://scrum-master.de

User avatar
derjanb
Site Admin
Posts: 2383
Joined: 20.01.06 02:16:15
Contact:

Re: Execute script automatically AND display context menu

Post by derjanb » 06.04.18 10:24:54

You can use GM_registerMenuCommand for this purpose. I do have the plan to add menu commands to the context menu as well, but no timeline yet.

http://tampermonkey.net/documentation.p ... enuCommand
ImageIf you like what I'm doing, please consider a donation here. Image

kriegaex
Posts: 4
Joined: 16.05.13 09:26:05
Contact:

Re: Execute script automatically AND display context menu

Post by kriegaex » 09.04.18 05:16:05

Thank you, I played around with it a bit. The problem with this approach is that
  • the automatic script should only run on a few sites, but
  • the menu entry should be available on every site (just in case).
While my automatic script's radius is limited by @include, the menu entry for the manual script should work for *://*/*. So unless you have another idea, I think I have to factor out the identical functionality into a separate, @required script, and just create two stubs with different settings for both cases. Not nice, but possible.

BTW, inline code formatting, i.e. fixed width font (not the BBCode "code" tag creating a new paragraph), would be nice to have here. Is it possible? The syntax help does not mention it.
--
Alexander Kriegisch
https://scrum-master.de

Post Reply