开发者

Loading my Greasemonkey script after another GM Script Loads

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开发者_运维技巧?


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

Drag-and-Drop with the mouse or press Alt-Up/Alt-Down to reorder scripts in this list


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜