Greasemonkey script not executed when unusual content loading is being used

Posted by Sam Brightman on Stack Overflow See other posts from Stack Overflow or by Sam Brightman
Published on 2010-05-20T09:50:23Z Indexed on 2010/05/21 11:30 UTC
Read the original article Hit count: 246

Filed under:
|
|

I'm trying to write a Greasemonkey script for Facebook and having some trouble with the funky page/content loading that they do (I don't quite understand this - a lot of the links are actually just changing the GET, but I think they do some kind of server redirect to make the URL look the same to the browser too?). Essentially the only test required is putting a GM_log() on its own in the script. If you click around Facebook, even with facebook.com/* as the pattern, it is often not executed. Is there anything I can do, or is the idea of a "page load" fixed in Greasemonkey, and FB is "tricking" it into not running by using a single URL?

If I try to do some basic content manipulation like this:

    GM.log("starting");
    var GM_FB=new Object;
    GM_FB.birthdays = document.evaluate("//div[@class='UIUpcoming_Item']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    for (i = GM_FB.birthdays.snapshotLength - 1; i >= 0; i--) {
       if (GM_FB.birthdayRegex.test(GM_FB.birthdays.snapshotItem(i).innerHTML)) {
          GM_FB.birthdays.snapshotItem(i).setAttribute('style','font-weight: bold; background: #fffe88');
       }
    }

The result is that sometimes only a manual page refresh will make it work. Pulling up the Firebug console and forcing the code to run works fine. Note that this isn't due to late loading of certain parts of the DOM: I have adding some code later to wait for the relevant elements and, crucially, the message never gets logged for certain transitions. For example, when I switch from Messages to News Feed and back.

© Stack Overflow or respective owner

Related posts about facebook

Related posts about greasemonkey