在另一个 GM 脚本加载后加载我的 Greasemonkey 脚本
我有两个在特定网址上加载的greasemonkey 脚本。如何确保在第一个 GM 脚本完成构建其页面元素之前不会加载第二个 GM 脚本。另外,如何控制 GM 脚本加载/运行的顺序?
I have two greasemonkey scripts loading on a particular url. How do I make sure my second GM script doesn't load until the first GM script completes building it's page elements. Also how do I control the order in which the GM scripts load/run?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 GreaseMonkey“管理用户脚本”UI 中选择您的脚本名称,然后按住 Alt 键并按 Down 键直到最后。
该UI中实际上有一条提示消息
Select you script Name in GreaseMonkey "Manage User Scripts" UI, and hold down the Alt key and press Down key until it goes last.
There is a hint message in that UI actually
S.Mark 描述了如何在 Greasemonkey 脚本管理界面(它的一部分)中管理执行顺序。但不能保证脚本 1 会在脚本 2 开始之前完成对 DOM 的所有操作。
如果脚本 2 依赖于脚本 1 的操作,则必须进行处理。
一种方法:让脚本 2 检查 DOM 中脚本 1 更改的某些状态(这表明脚本 1 效果已完成)。在脚本 2 中,使用 window.setTimeout() 保持递归循环并定期检查信号状态,然后在满足条件后中断并开始脚本 2 的主要工作。
另一种方法是:将两个脚本合并为一个,并适当地对代码块进行排序。
S.Mark described how to manage the order of execution in the Greasemonkey script management interface, which is part of it. But it can't be guaranteed that Script 1 will finish effecting all its operations on the DOM before Script 2 begins.
If Script 2 is dependent on the actions of Script 1, that has to be handled.
One approach: Have Script 2 check the DOM for some state changed by Script 1 (which signals Script 1 effects have completed). In Script 2 stay in a recursive loop with window.setTimeout() and routinely check for the signalling state, then break out and begin the main work of Script 2 once the condition has been met.
Another approach altogether: combine the two scripts into one, and order the blocks of code appropriately.