Jump to content

User:DavidBrooks/recolor.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Include this with code like the following:
// document.write('<script type="text/javascript" src="' 
//  + 'http://en.wikipedia.org/w/index.php?title=User:DavidBrooks/recolor.js' 
//  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

var recol_onoff;
recol_onoff=0;

function recolorone(tag, which) {
	tag.style.color = which?"#000000":"";
	tag.style.textDecoration = which?"none":"";
}

function glow() {
	recolorone(this, 0); /* Return to default (style sheet) coloring */
}

function unglow() {
	recolorone(this, 1); /* Force hidden links */
}

function recolor() {
recol_onoff = 1 - recol_onoff;
var tagid;
var alltags = document.getElementById("article").getElementsByTagName('A');
for (var thistag = 0; alltags[thistag]; thistag++) {
	tagid = alltags[thistag];
	recolorone(tagid, recol_onoff);
	if (recol_onoff) {
		tagid.onmouseover = glow;
		tagid.onmouseout = unglow;
	} else {
		tagid.onmouseover = tagid.onmouseout = null;
	}
}
return false;
}

function tagh() {
	document.getElementsByTagName('h1')[0].onclick = recolor;
}

if (window.addEventListener) window.addEventListener("load",tagh,false);
else if (window.attachEvent) window.attachEvent("onload",tagh);