Wrap your Greasemonkey code in a function and then set a document change event-handler to call it. Like so...
/*--- To "refire" our Greasemonkey code on AJAX changes, we wrap it in
a function and call it on a DOM change event.
*/
var zGbl_DOM_ChangeTimer = '';
var bGbl_ChangeEventListenerInstalled = false;
/*--- Run everything after the document has loaded. Avoids race-
conditions and excessive "churn".
*/
window.addEventListener ("load", MainAction, false);
function MainAction ()
{
if (!bGbl_ChangeEventListenerInstalled)
{
bGbl_ChangeEventListenerInstalled = true;
/*--- Notes:
(1) If the ajax loads to a specific node, add this
listener to that, instead of the whole body.
(2) iFrames may require different handling.
*/
document.addEventListener ("DOMSubtreeModified", HandleDOM_ChangeWithDelay, false);
}
//--- ****************************
//--- *** YOUR CODE GOES HERE. ***
//--- ****************************
}
function HandleDOM_ChangeWithDelay (zEvent)
{
/*--- DOM changes will come hundreds at a time, we wait a fraction
of a second after the LAST change in a batch.
*/
if (typeof zGbl_DOM_ChangeTimer == "number")
{
clearTimeout (zGbl_DOM_ChangeTimer);
zGbl_DOM_ChangeTimer = '';
}
zGbl_DOM_ChangeTimer = setTimeout (function() { MainAction (); }, 222); //-- 222 milliseconds
}