Jump to content

User:Guarapiranga/short-tabs.js

From Wikipedia, the free encyclopedia
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.
// Fork from [[User:DannyS712/short-tabs.js]] (who in turn forked it from [[User:Enterprisey/short-tab-titles.js]])
//
// Install with:
// <code><nowiki>		{{subst:Iusc|User:Guarapiranga/short-tabs.js}}																	</nowiki></code>
// or with
// <code><nowiki>		importScript( 'User:Guarapiranga/short-tabs.js' ); // Backlink: [[User:Guarapiranga/short-tabs.js]] 			</nowiki></code> 
//
// If forking this script, please note my contributions / give me credit
(function(){
var prepended = "";
var set_title = "";
$( function() {	all(); } );
$(document).on( "mousemove", check );

/*** Change the title - main function ***/
function all () {
	var t = document.title;
	t = preprocess( t );
	t = prepend( t );
	if ( mw.config.get('wgNamespaceNumber') > 1 ) t = run ( t );
	set_title = prepended + t;
	console.log( set_title );
	document.title = set_title;
}

/*** Don't run if title won't change ***/
function check () {
	if ( document.title === set_title ) return;
	all();
}

/*** Run, actions based on namespace, most just replace talk ***/
function run ( t ){
	var four = t.substring( 0, 4 );
	if( four  === "User" ) t = "U" + talk( t.substring( 4 ));
	else if( four === "File" ) t = "F" + talk( t.substring( 4 ));
	else if( four === "Help" ) t = "H" + talk( t.substring( 4 ));
	else {
		if ( t.substring( 0, 5 ) === "Draft" ) t = "D" + talk( t.substring( 5 ));
		else {
			var six = t.substring( 0, 6 );
			if( six === "Portal" ) t = "P" + talk( t.substring( 6 ));
			else if( six === "Module" ) t = "M" + talk( t.substring( 6 ));
			else {
				var eight = t.substring( 0, 8 );
				if( eight === "Category" ) t = "CAT" + talk( t.substring( 8 ));
				else if( eight === "Template" ) t = "T" + talk( t.substring( 8 ));
				else {
					var nine = t.substring( 0, 9 );
					if( nine === "Wikipedia" ) t = "WP" + talk( t.substring( 9 ) );
					else if( nine === "MediaWiki" ) t = "MW" + talk( t.substring( 9 ));
	}}}}
	return t;
}

/*** Shorten the first part of the title ***/
function prepend ( t ){
	if ( t.substring( 0, 8 ) === "Editing " ) {
		prepended = "Edit ";
		t = t.substring( 8 );
	} else if ( t.substring( 0, 9 ) === "Creating " ) {
		prepended = "Create ";
		t = t.substring( 9 );
	} else if ( t.substring( 0, 23 ) === "User contributions for "){
		prepended = "Contribs - ";
		t = t.substring( 23 );
	}
	return t;
}

/*** Get rid of " - Wikipedia" at the end of each title ***/
function preprocess ( t ){
	if ( t.substring(t.length - 12, t.length) === " - Wikipedia" ) t = t.substring(0, t.length - 12);
	return t;
}

/*** Shorten names for specified pages (useful if they have lots of subpages) ***/
function shorten ( t ){
	t = t.replace(/Wikipedia/gi, "WP");
	t = t.replace(/Category/gi, "CAT");
	var sub = t.substring ( 0, 11 );
	if ( sub === "In the news" || sub === "Arbitration" || sub === "Village pum" || sub === "Did you kno" || sub === "Manual of S" || sub === "Long-term a" || sub === "Deletion re" || sub === "Files for d" || sub === "Articles fo" || sub === "Miscellany " || sub === "Templates f" || sub === "Redirects f" || sub === "Requests fo" || sub === "Categories " || sub === "Sockpuppet " || sub === "Administrat" || sub === "Contributor" || sub === "WikiProject" ){
		//Wikipedia pages
		if (t.substring ( 0, 11 ) === "In the news" ) t = "ITN" + t.substring( 11 );
		else if (t.substring ( 0, 11 ) === "Arbitration" ) t = "Arb" + t.substring( 11 );
		else if (t.substring ( 0, 12 ) === "Village pump" ) t = "VP" + t.substring( 14, 15 ).toUpperCase();
		else if (t.substring ( 0, 12 ) === "Did you know" ) t = "DYK" + t.substring( 12 );
		else if (t.substring ( 0, 15 ) === "Manual of Style" ) t = "MoS" + t.substring( 15 );
		else if (t.substring ( 0, 15 ) === "Long-term abuse" ) t = "LTA" + t.substring( 15 );
		else if (t.substring ( 0, 15 ) === "Deletion review" ) t = "DelRev" + t.substring( 15 );
		else if (t.substring ( 0, 20 ) === "Files for discussion" ) t = "FfD" + t.substring( 20 );
		else if (t.substring ( 0, 20 ) === "Requests for comment" ) t = "RfC" + t.substring( 20 );
		else if (t.substring ( 0, 21 ) === "Articles for deletion" ) t = "AfD" + t.substring( 21 );
		else if (t.substring ( 0, 22 ) === "Requests for adminship" ) t = "RfA" + t.substring( 22 );
		else if (t.substring ( 0, 23 ) === "Miscellany for deletion" ) t = "MfD" + t.substring( 23 );
		else if (t.substring ( 0, 24 ) === "Templates for discussion" ) t = "TfD" + t.substring( 24 );
		else if (t.substring ( 0, 24 ) === "Redirects for discussion" ) t = "RfD" + t.substring( 24 );
		else if (t.substring ( 0, 24 ) === "Requests for permissions" ) t = "PERM" + t.substring( 24 );
		else if (t.substring ( 0, 25 ) === "Categories for discussion" ) t = "CfD" + t.substring( 25 );
		else if (t.substring ( 0, 25 ) === "Sockpuppet investigations" ) t = "SPI" + t.substring( 25 );
		else if (t.substring ( 0, 27 ) === "Administrators' noticeboard" ) t = "AN" + t.substring( 27 );
		else if (t.substring ( 0, 36 ) === "Contributor copyright investigations" ) t = "CCI" + t.substring( 36 );
		//WikiProject pages
		else if (t.substring ( 0, 33 ) === "WikiProject Articles for creation" ) t = "AfC" + t.substring( 33 );
	}
	return t;
}

/*** Replate "talk:" with "-T:" ***/
function talk( t ){
	var pre = "";
	if ( t.substring ( 0, 6 ) === " talk:" ) {
		pre = "T:";
		t = t.substring( 6 );
	} else if ( t.substring ( 0, 1 ) === ":" ) {
		pre = ":";
		t = t.substring( 1 );
	}
	return pre + shorten ( t );
}
}())