User:DannyS712/short-tabs.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:DannyS712/short-tabs. |
// Install with:
// <code><nowiki> {{subst:Iusc|User:DannyS712/short-tabs.js}} </nowiki></code>
// or with
// <code><nowiki> importScript( 'User:DannyS712/short-tabs.js' ); // Backlink: [[User:DannyS712/short-tabs.js]] </nowiki></code>
//
// Special thanks to User:Enterprisey and their script, [[User:Enterprisey/short-tab-titles.js]], which I forked.
// 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 = "File" + talk( t.substring( 4 ));
else if( four === "Help" ) t = "Help" + talk( t.substring( 4 ));
else {
if ( t.substring( 0, 5 ) === "Draft" ) t = "Draft" + talk( t.substring( 5 ));
else {
var six = t.substring( 0, 6 );
if( six === "Portal" ) t = "Portal" + talk( t.substring( 6 ));
else if( six === "Module" ) t = "Module" + 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 = "Template" + 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 = "MediaWiki" + 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( 12 );
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 );
}
}())