Jump to content

User:Danski454/code-link.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Danski454 (talk | contribs) at 14:37, 3 January 2019 (fix). 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.
(function ($, mw){
	
	function doWikilinks(){
		$(".c, .c1, .cm").each(function(){
			var text = $(this).html();
			var match;
			var re = /\[\[([^[\]|<>{}]+)(?:\|.*?)?\]\]/;
			while(re.match(text)){
				match = re.match(text);
				var url = mw.config.get("wgArticlePath").replace("$1",
					encodeURIComponent(match[1].replace("&quot;", '"').replace("&#x27;", "'")
					.replace("&#x2F;", "/").replace("&amp;", "&").replace(" ", "_")));
				text = text.replace(match[0], '<a class="code-link" href="' + url + '">' + match[0] + '</a>');
			}
			$(this).html(text);
		});
	}
	
	function doExternalLinks(){
		
	}
	
	$(document).ready(function(){
		if ( mw.config.get("wgIsArticle") && ["javascript", "css", "Scrubinto"].indexOf(mw.config.get("wgPageContentModel")) !== -1 ){
			doWikilinks();
			doExternalLinks();
		}
	});
	
})(jQuery, mediaWiki);