Jump to content

User:Technical 13/Scripts/Gadget-codeBacklinks.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Technical 13 (talk | contribs) at 19:00, 2 February 2014 (Technical 13 moved page User:Technical 13/SandBox/Gadget-codeBacklinks.js to User:Technical 13/Scripts/Gadget-codeBacklinks.js without leaving a redirect: Moving stable script). 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.
var PCM = mw.config.get( "wgPageContentModel" );
$("pre.source-" + PCM).find("span.co1, span.coMULTI").each(function(){
	var codeComment = $(this).html().substr($(this).html().indexOf("[["));
	var wikiLinkPipe = "";
	var extraLinks =  "";
	while(codeComment.indexOf("[[") !== -1 && codeComment.indexOf("]]") !== -1){
		if(codeComment.indexOf("|") !== -1 && codeComment.indexOf("|") > codeComment.indexOf("[[") && codeComment.indexOf("|") < codeComment.indexOf("]]")){
			var wikiLink = codeComment.slice(codeComment.indexOf("[[") +2, codeComment.indexOf("|"));
			wikiLinkPipe = codeComment.slice(codeComment.indexOf("|"), codeComment.indexOf("]]"));
		} else {
			var wikiLink = codeComment.slice(codeComment.indexOf("[[") +2, codeComment.indexOf("]]"));
		}
		var replaceWikiLink = codeComment.slice(codeComment.indexOf("[["), codeComment.indexOf("]]") +2);
		codeComment = codeComment.substr(codeComment.indexOf("]]") +2);
		if(wikiLink.search("Special:") === -1){
			extraLinks =  " <small style=\"font-style: normal;\">( <a href=\"" + mw.config.get("wgServer") + mw.config.get("wgScriptPath") + "/index.php?title=" + wikiLink + "&action=edit#editform\" title=\"Please use [show preview] before saving.\">edit</a> | <a href=\"" + mw.config.get("wgServer") + mw.config.get("wgArticlePath").replace("$1", "Special:WhatLinksHere/" + wikiLink) + "\" title=\"A list of all wiki pages that link here.\">wlh</a> )</small>";
		}
		$(this).html($(this).html().replace(replaceWikiLink, "<b>[[</b><a href=\"" + mw.config.get("wgServer") + mw.config.get("wgArticlePath").replace('$1', wikiLink) + "\" title=\"" + wikiLink + "\">" + wikiLink + "</a><b>" + wikiLinkPipe + "]]</b>" + extraLinks));
		wikiLinkPipe = "";
		extraLinks =  "";
	}
});