I have conquered Xanga's oh-so-tricky ad header, muahahaha. Blocking the ad is trivial, but removing the header itself is another matter. I've long been annoyed at Firefox for displaying the empty space in which the ad should reside. Safari doesn't. But anyway... I'm Firefoxing more these days so I figured I better just fix it.
So enter Greasemonkey, a Firefox necessity which allows you to write javascript to alter other people's websites for your own enjoyment, sanity, etc. Greasemonkey does nothing on its own, it provides a facility for "user scripts" to run on a specific page or site.
So I looked for some Xanga-related user scripts and the available scripts do a fine job of hiding the <div> that should contain the header but they don't address killing the actual header, which it turns out is generated dynamically in javascript and given a random 8-character id. They don't want you to be able to do this, I see. Since the header is written out by javascript, hiding the <div> is not sufficient. You gotta remove the <div> by ID after it is filled.
So the right answer is to parse the page looking for the script that creates the header, snarf the ID, and make its parent send it to never-never land. I have the power! Anyway, here 'tis:
function xpath(query) {
return document.evaluate(query, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
}
function doedit() {
var theDiv = xpath('//div[@style="height: 130px;"]').snapshotItem(0);
theDiv.style.display = "none";
var divid = "";
allscripts = document.getElementsByTagName("script")
for (var i=0; i < allscripts.length; i++) {
s = allscripts[i];
if (s.innerHTML.length > 50) {
continue;
}
if (s.innerHTML.match(/txtout/g)) {
divids = s.innerHTML.match(/'[a-zA-Z0-9]*'/g);
divid = divids[0].split("\'")[1];
}
}
if(divid != "") {
var adsbox = document.getElementById(divid);
if (adsbox) {
adsbox.parentNode.removeChild(adsbox);
}
}
}
doedit();
// Or use this if doedit() is getting called early... but the above works for me
// window.addEventListener('load', doedit, true);
Technorati Tags: code, greasemonkey, xanga





Recent Comments