如何仅重新加载用户脚本,即不重新加载页面? [英] How to reload only a userscript, i.e. without reloading the page?
问题描述
我正在为Web应用程序编写Greasemonkey用户脚本,该脚本需要配置步骤,然后才能实际测试用户脚本的功能.因此,每次我重新加载页面(从更新的文件刷新用户脚本)时,都必须在测试之前重新配置Web应用程序.不用说,它很快就会变旧.
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.
推荐答案
通常不可行.
正如其中一位合作者在GreaseMonkey的GitHub存储库中的此问题中所述所有脚本都会使页面发生变异,从而使重复执行脚本成为问题.
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:
- 确保您仔细评估它会对页面产生什么影响,并且
- 实施清理代码,以准备页面以重复执行脚本.
这篇关于如何仅重新加载用户脚本,即不重新加载页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!