Folks, I'm developing a user script to change the header color of Facebook to a distinct red to remind page-owners when they're using FB as a page owner, rather than as their own identity. This is intended to prevent accidental grief caused if they post what is intended to be a personal message as the page owner (usually a "brand").
The problem is that I'm getting an error (Uncaught TypeError: Cannot read property 'children' of null) at line 15 on some pages that do NOT match the @include and @match lines, indicating that either: - The @include/@match lines are not effective or - The pages in question *somehow* match those lines I have hacked around this issue by wrapping the content of the script with a (should-be) redundant check to see if the current page is on Facebook, but I don't think that this is the way to go. BTW: It's not just this script — several others are exhibiting the same failure, but they target pages behind our firewall, so I can't share them here. Thanks, Dave // ==UserScript== // @namespace http://www.ryanland.com/greasemonkey // @name Warn User that she or he is using FB as page // @match *://*.facebook.com/* // @include *://*.facebook.com/* // @description Changes page header to warn when logged in to FB as a page user, not personal account. // ==/UserScript== function warnIfUsingAsPage () { xpath="//a[contains(@onclick,'pageIdentitySwitchForm')]" var candidates = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); // The following is a TOTALLY fragile and unreliable method of detecting when using FB as a page, // but it seems to work, at least for me, at least for now, so there. if (document.getElementById("pageHead").children[1].className == "noMessages") { console.log("Hi, " + document.getElementsByClassName("navIdentityPic")[0].children[0].href.split(/\//)[3] + ". You're using FB as " + document.getElementById("navHome").nextSibling.children[0].href.split(/\//)[3] ) var t = document.createTextNode("#pageHead, #headNav { background-color: #CC6666 !important; } #headNav { border: 1px solid #993333 !important; }"); var root = (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]); var ss = document.createElement("style"); ss.appendChild(t); ss.setAttribute("type","text/css"); ss.setAttribute("id","fb_use_as_flag"); root.appendChild(ss); } else { console.log("You're using FB as yourself.") } } if (location.href.match(/facebook/) == "facebook") { window.setTimeout(warnIfUsingAsPage, 500); } -- You received this message because you are subscribed to the Google Groups "greasemonkey-users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en.
