GregH
GregH

Reputation: 12858

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?

Upvotes: 0

Views: 1900

Answers (2)

micahwittman
micahwittman

Reputation: 12476

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.

Upvotes: 1

YOU
YOU

Reputation: 123831

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

Upvotes: 1

Related Questions