The answer below is DEPRECATED. You should use Use MutationObserver or setInterval instead. See this: Greasemonkey script to work on dynamically loaded posts on Facebook
Since you are using Firefox, you can trigger off the DOMSubtreeModified
event.
To do this, first wrap the code part of your current script in a function; for example:
// ==UserScript==
// @name
// ==/UserScript==
function LocalMain ()
{
//--- Do all of your actions here.
}
LocalMain (); //-- Fire GM script once, normally.
Next, find DOM node changed when clicking on "Next Page". Once you've identified the correct node, you can set the event listener. But, you also need a short time delay because the node changes come hundreds at a time and you need to wait until the current batch is done.
So, putting it all together, the code looks like this:
if (window.top != window.self) //don't run on frames or iframes
return;
function LocalMain ()
{
//--- Do all of your actions here.
}
LocalMain (); //-- Fire GM script once, normally.
var ContentChangedByAJAX_Timer = '';
//--- Change this next line to find the correct element; sample shown.
var ContentWrapperNode = document.getElementById ('THE ID OF DOM NODE GOT UPDATE WHEN CLICKING ON NEXT PAGE');
ContentWrapperNode.addEventListener ("DOMSubtreeModified", PageBitHasLoaded, false);
function PageBitHasLoaded (zEvent)
{
/*--- Set and reset a timer so that we run our code (LocalMain() ) only
AFTER the last post -- in a batch -- is added. Adjust the time if needed, e.g. 3 seconds.
*/
if (typeof ContentChangedByAJAX_Timer == "number")
{
clearTimeout (ContentChangedByAJAX_Timer);
ContentChangedByAJAX_Timer = '';
}
ContentChangedByAJAX_Timer = setTimeout (function() {LocalMain (); }, 3000);
}