How to reload only a userscript, i.e. without reloading the page?

ⅰ亾dé卋堺 提交于 2019-12-31 04:09:51

问题


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.


回答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




回答2:


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.


来源:https://stackoverflow.com/questions/29200711/how-to-reload-only-a-userscript-i-e-without-reloading-the-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!