3

I'm working on a Greasemonkey userscript for a web app that needs configuration steps before I can actually test my userscript's functionality. So every time I reload the page – to refresh my userscript from the updated file –, I have to reconfigure the web app before testing. Needless to say, this gets old very quickly.

Is there a way to reload only the userscript, preferably from the userscript itself? I would want to e.g. bind the reload to a keyboard shortcut.

I thought that this must be a very common need, but I came up empty-handed when trying to find a solution.

Leaky
  • 3,088
  • 2
  • 26
  • 35
  • possible dupe http://stackoverflow.com/q/10700127/526704 – DLeh Mar 22 '15 at 22:42
  • 2
    (1) If you don't use `GM_` functions, **do all of your dev in the console.** Only when the code works, put it in a script. (2) Even with GM funcs, can usually test most of the code in the console. (3) **Make a separate user script that does all of the configuration steps automatically.** (4) If you are really into pain, make your script AJAX in new code and `eval()` it *in the script scope*. Don't even think about this unless your script relies heavily on `GM_` functions. – Brock Adams Mar 22 '15 at 23:25

2 Answers2

1

Might want to have alook into AJAX for this then, it's a tool that interacts with databases without refreshing the webpage. I.E - dynamic webpages.

Might help, just do a general google browse and see if it applies.

https://www.w3schools.com/xml/ajax_intro.asp

Antoine Colson
  • 660
  • 5
  • 8
0

Generally not feasible.

As one of the collaborators remarked on this issue in GreaseMonkey's GitHub repo, almost all scripts mutate the page in ways that makes repeated script execution problematic.

I overlooked this fact in my original question – my script does mutate the page in ways that makes repeated script execution problematic.

If you want to implement script reload, and you find a feasible method to do that:

  • make sure you carefully evaluate what effect will it have on the page, and
  • implement clean-up code to prepare the page for the repeated execution of your script.
Leaky
  • 3,088
  • 2
  • 26
  • 35