Greasemonkey: [suggestion] clean function: A function to clean what the script has done when disabling it

Created on 10 Apr 2016  路  7Comments  路  Source: greasemonkey/greasemonkey

Don't know if this was suggested or implemented already but I'm going to write it anyway.
My idea is an API function that get invoked when the user disable a specific script inside a web page.
For example, i create a user script that adds some functions to facebook and also changes some of the tree nodes and styling obviously, so when a user is in a facebook page and want to disable the script from greasmonkey toolbar icon a function in the script (GM_clean maybe ?) get invoked, this function can be used to clean what the script has done to the web page (removing nodes and styles, cleaning some memory maybe).
Also a second function (GM_Enabled maybe) to be run when the script is enabled again

All 7 comments

You can refresh the page.

Any use case that the user will dis/enable a script often?

You can refresh the page.

No kidding !

Any use case that the user will dis/enable a script often?

I didn't say often, i personally use it when looking for a script that does a specific functionality, i always find multiple scripts that does the same functionality so i download them both and go to the webpage and then disable and enable each of the scripts to see which script does the job better

:-1:

Due to how many changes a script could make, there is no way for GM to do anything to "clean" what was done to a page. Creating a GM_onEnable and GM_onDisable would be interesting, but I would say most authors wouldn't use them, or if they did, they probably wouldn't reverse all changes.

For your use-case, I would personally say the best way to analyze multiple scripts is to analyze them separately: enable one, test it, disable, with refreshes in between.

No kidding !

It was meant seriously (it's used commonly)...

Agreed, this would be useful only if every script used it, but few would bother.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Powersource picture Powersource  路  5Comments

byzod picture byzod  路  9Comments

an-electric-sheep picture an-electric-sheep  路  11Comments

lainverse picture lainverse  路  3Comments

noscript picture noscript  路  16Comments