User:Manishearth/scriptlinks.js

This is an old revision of this page, as edited by Manishearth (talk | contribs) at 15:50, 27 March 2010. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
//Test stuff:
// [[User:Manishearth]] [[User:Manishearth|boom]]
// [http://en.wikipedia.org] [boom.com boom]
// http://www.wikia.com/blooper/testlink
/* [[Boomdeyada]] */
/* [[Boomdeyada]] 
BOOM 
*/
importScript("boom.js")
importScript('boom.js')
function scriptLinks(className){
	pre = getElementsByClassName(document, "pre", "source-javascript");
	for(i = 0; i < pre.length; i++) {
		par = getElementsByClassName(pre[i], "span", className);
		for(j = 0; j < par.length; j++) {
			par[j].innerHTML=par[j].innerHTML.replace(/\[\[([^\]\|]*)\]\]/g,"<a href='"+wgServer+"/wiki/$1'>$1</a>");
			par[j].innerHTML=par[j].innerHTML.replace(/\[\[([^\]\|]*)[\|]?([^\]]*)\]\]/g,"<a href='"+wgServer+"/wiki/$1'>$2</a>");
			par[j].innerHTML=par[j].innerHTML.replace(/\[(http[s]?:\/\/[^\]\s]*)\]/g,"<a href='$1'>$1</a>");
			par[j].innerHTML=par[j].innerHTML.replace(/\[(http[s]?:\/\[^\]\s]*)[\s]?([^\]]*)\]/g,"<a href='$1'>$2</a>");
			//par[j].innerHTML=par[j].innerHTML.replace(/[^\"\>][\s]?+(http[s]?:\/\/[^\s]*)/g,"<a href='$1'>$1</a>");
		}
	}
}
addOnloadHook(function(){
scriptLinks("co1");
scriptLinks("co2");
scriptLinks("coMULTI");
importScript_links();
});

//Taken from [[User:AoV2/importScript_links]]
function importScript_links(){
	pre = getElementsByClassName(document, "pre", "source-javascript");
	for(i = 0; i < pre.length; i++) {
		par = getElementsByClassName(pre[i], "span", "br0");
		for(j = 0; j < par.length; j++) {
			if(par[j].innerHTML != "(") continue;
			o = par[j].previousSibling;
			if(o.nodeType != 3) continue;
			if(!o.data.match(/\bimportScript\s*$/)) continue;
			s = par[j].nextSibling;
			var h= s.innerHTML + "";
			var h2=h+"";
			var h3=h2+""
			var q;
			var quo;
			if(s.className != "st0") continue;
			else if(h.match(/"([^"']+)"/)) {
				q = /"([^"']+)"/g;
				quo='"'
			}else if(h2.match(/'([^'"]+)'/)) {
 				q = /'([^'"]+)'/g;
				quo="'"
			}else continue;
			var h4=h3+"";
			p = encodeURIComponent(h3.replace(q, "$1").replace(/[_\s]+/g, "_")).replace(/%2F/g, "/");
			s.innerHTML = quo + '<a href="' + wgArticlePath.replace("$1", p) + '">' + hh.replace(q, "$1") + '</a>' + quo;
			}
		}
	}