[Feature] Higher/Lower Order (or Highlight/Grey Out) for the script (not) applying the current URL in SPA
cyfung1031 opened this issue · comments
Motivation
In YouTube, it is Single Page Application, so all of them have to set to @match https://www.youtube.com/*
to ensure them can be executed after the SPA is switched to the desired page (url changed due to history state)
Motivation 1: Currently for such a UserJS used in SPA, it is not clear enough to let users know which page(s) it will apply.
Motivation 2: Too many scripts shown under the YouTube SPA. Some are not really "working" in the current URL
Currently the ON/OFF is 100% equal to the @match
which is not enough for SPA
I want some ways to grey out the option so that user can know that it is not applying to the current page.
But this can be wrong (code is actually executing) => might be just some lighter/darker colors.
so I hope that there can be some config to make the script go up/down in the menu.
Proposed Solution
In addition to @match
, hope there can be @match-active
@match-inactive
It can handle the SPA history state change and popstate change as well.
If @match-active
is fulfilled (supposed @match
is matched first), the script row will be shown in a HIGHER position (or color highlight)
If @match-inactive
is fulfilled (supposed @match
is matched first), the script row will be shown in a LOWER position (or fade-out color)
these are just for the display in the menu. no effect on the actual JS execution.
Use Cases
Example Script: https://greasyfork.org/en/scripts/489605-youtube-watch-later-remove-button-on-hover/code
// ==UserScript==
// @name YouTube Watch Later Remove Button on Hover
// @namespace http://tampermonkey.net/
// @version 0.6.1
// @description Show a remove button on hover over video thumbnails in the Watch Later list
// @license MIT
// @match https://www.youtube.com/*
// @match-active https://www.youtube.com/playlist?list=WL
// @run-at document-start
// @grant none
// @inject-into page
// ==/UserScript==
We can't know if a script is not active on the current SPA route, because it depends on its inner logic. The document is the same for a SPA, so Violentmonkey cannot "activate" or "deactivate" a running script. Such script can signal its state via GM_registerMenuCommand.
Ah, you already mentioned that. Geez I'm so impatient, sorry.
We won't implement @match-active
idea because as I explained above we can't be sure the script is really active or inactive, so it's wrong to just trust it blindly.
Maybe we can add GM_setMenuState which will do something to the script name in the popup or add/change its icon?
@gera2ld
Yeah sounds like a good idea.
We can't know if a script is not active on the current SPA route, because it depends on its inner logic. The document is the same for a SPA, so Violentmonkey cannot "activate" or "deactivate" a running script. Such script can signal its state via GM_registerMenuCommand.
Yes. the idea is that, there can be some ways to move the script upwards or downwards as the script is not really applying to the current page URL.
// @xxxxxxxx https://www.youtube.com/playlist?list=WL
can help people to know which URL is applying on.
Other ways (like GM_setMenuState
as you mentioned) are also acceptable although config inside the program makes it less noticeable to the general users.