User:Mr.Z-man/whatlinksHighlight.js

function whatlinksHighlight { if (mw.config.get('wgPageName') == "Special:Whatlinkshere") { if (document.URL.indexOf('&') != -1) { title = document.URL.substring(document.URL.indexOf('Special:Whatlinkshere/')+22, document.URL.indexOf('&')); } else { title = document.URL.substring(document.URL.indexOf('Special:Whatlinkshere/')+22); }		linkadd = "?highlight=" + title + "#whatlink"; whatcode = document.getElementsByTagName('ul')[0]; var redirects = new Array; if (whatcode.getElementsByTagName('ul')[0]) { var redirregex = /\(links<\/a>\)<\/span>/g; //"			redirects = whatcode.innerHTML.match(redirregex);			for (var k in redirects) {				redirects[k] = redirects[k].toString.replace(/\(links<\/a>\)<\/span>/, '$1'); //" }		}					whatlinks = whatcode.getElementsByTagName('a'); for (var i = 0;i<whatlinks.length; i++) { if (whatlinks.item(i).href.toString.indexOf('Special:Whatlinkshere') == -1 && whatlinks.item(i).href.toString.indexOf('&redirect=no') == -1) { whatlinks.item(i).href += linkadd; }		}		if (whatcode.getElementsByTagName('ul')[0]) { for (var m=0; m<redirects.length; m++) { whatlinks = whatcode.getElementsByTagName('ul')[m].getElementsByTagName('a'); for (var i = 0;i<whatlinks.length; i++) { if (whatlinks.item(i).href.toString.indexOf('?highlight=') != -1) { target = whatlinks.item(i).href.toString; whatlinks.item(i).href = target.replace(/\?highlight=\S*?#whatlink/, "?highlight=" + redirects[m] + "#whatlink"); }				}			}		}					}	if (document.URL.indexOf('?highlight=') != -1) { title = document.URL.substring(document.URL.indexOf('?highlight=')+11, document.URL.indexOf('#whatlink')); title = title.replace(/_/g, " "); title = unescape(title); for (var i in document.links) { if (document.links[i].title == title) { document.links[i].style.backgroundColor = '#FDE910'; document.links[i].name = 'whatlink' }		}	} } addOnloadHook(whatlinksHighlight);