User:Hu12/alwayssecurewikipedia.js

/* Script to rewrite "http://X.wikipedia.org/Y" external links (e.g., copied-and-pasted links to diffs) to "https://secure.wikimedia.org/wikipedia/X/Y" when browsing from https://secure.wikimedia.org, so that clicking them doesn't take you off the site. */

addOnloadHook(function {	if (wgServer != 'https://secure.wikimedia.org') return;	var re = /^http\:\/\/(.*?)\.wikipedia\.org(\/.*?)$/;	var links = document.getElementsByTagName('a');	for (var i = links.length; i--;) {		var link = links[i];		if (matches = link.href.match(re)) {			if (matches[1] == 'mail') continue;			if (matches[2] == '/') matches[2] = '/wiki/';			var n = 'https://secure.wikimedia.org/wikipedia/' + matches[1] + matches[2];			link.href = n; link.title = n;			if (link.innerHTML.match(re)) link.innerHTML = n;		}	} });