MediaWiki:Common.js/obamageddon
/* This is an archive of the obamageddon code used during the 2010 US election season */
/*
Obamageddon Warning Meter - By Jeeves.
- /
function handle_obamageddon(data) { var obamageddonIndex = 0;
var pages = data.query.pages; for (var page in pages) { var text = pages[page].revisions[0]["*"]; var startIndex = 0; var endIndex = 0;
while (-1 != startIndex) { var startIndex = text.indexOf("[[File:", startIndex);
if (-1 != startIndex) { startIndex += 7; endIndex = text.indexOf("]]", startIndex); if (-1 == endIndex) break; var filename = text.substr(startIndex, endIndex-startIndex); if (-1 != filename.search(/obama/i)) ++ obamageddonIndex; } }
break; }
// update all obamageddon tables var tables = document.getElementsByTagName("table"); for (var i = 0; i < tables.length; ++i) { if (hasClass(tables[i], "obamageddon")) { var cells = tables[i].rows[0].cells; for (var j = obamageddonIndex; j < 10; ++j) { cells[j].style.backgroundColor = "white"; } } } }
function eval_obamageddon_index() { // check if an obamageddon update is required var tables = document.getElementsByTagName("table"); for (var i = 0; i < tables.length; ++i) { if (hasClass(tables[i], "obamageddon")) { // yep. fetch the page text. var script = document.createElement("script"); script.src = "http://conservapedia.com/api.php?action=query&prop=revisions&titles=Template:Mainpageright&rvprop=content&format=json&callback=handle_obamageddon"; document.body.appendChild(script); break; } } }
addOnloadHook(eval_obamageddon_index);