User:Fred Gandt/wikilinkPlus.js

/* Hold down an ALT key when clicking any link to bring up ALTernative related destinations */

( function( d ) {	function init {		var talk = function( ttl, rslt ) {				rslt = ( /^(?:Talk|(\w+)_talk)\:((?:[^\/]+)(?:\/[^]+)?)$/ ).exec( ttl );				if ( !!rslt ) {					if ( rslt[ 1 ] ) {						return [ rslt[ 1 ] + ":" + rslt[ 2 ], "Page" ];					}					return [ rslt[ 2 ], "Article" ];				}				rslt = ( /^(?:(\w+)\:)?((?:[^\/]+)(?:\/[^]+)?)$/ ).exec( ttl );				return rslt[ 1 ] ? [ rslt[ 1 ] + "_talk:" + rslt[ 2 ], "Talk" ] : [ "Talk:" + rslt[ 2 ], "Talk" ];			},			user = function( ttl, usr ) {				usr = ( /^User(?:_talk)?\:(?:([^\/]+)(?:\/[^]+)?)/ ).exec( ttl );				return !!usr ? 'Contribs' : "";			},			extraLinks = function( ttl, tlk ) {				tlk = talk( ttl );				return '' + tlk[ 1 ] + 'EditHistory' + user( ttl ); };		mw.loader.load( "/w/index.php?title=User:Fred_Gandt/wikilinkPlus.css&action=raw&ctype=text/css", "text/css" ); d.getElementById( "mw-content-text" ).addEventListener( "click", function( evt, t, tt, ewl ) {			if ( evt.altKey ) {				t = evt.target;				tt = t.title;				if ( t.tagName.toLowerCase === "a" && !t.getAttribute( "class" ) && !t.parentElement.classList.contains( "mw-editsection" ) && tt && tt.substring( 0, 8 ) != "Special:" ) {					evt.preventDefault;					ewl = d.createElement( "div" );					ewl.setAttribute( "class", "fg-wikilink-plus-newi" );					ewl.innerHTML = extraLinks( mw.util.wikiUrlencode( tt ) );					t.appendChild( ewl );				}			}		}, false ); }	$( d ).ready( init ); } ( document ) );