Jump to content

User:Technical 13/SandBox/Gadget-extraTabs.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.
var nsNum = mw.config.get('wgNamespaceNumber');
var specialPageName = mw.config.get('wgCanonicalSpecialPageName');
var rawPageName = mw.config.get('wgTitle');
var artPath = mw.config.get('wgArticlePath');
var fullScriptPath  = mw.config.get('wgServer') + mw.config.get('wgScriptPath');
var isPage = false, isTalk = false, isSand = false, isTest = false, isDoc = false, isDiff = false, isET = false;
var tabName = "tab", tabLocation = "//en.wikipedia.org/w/index.php?title=User_talk:Technical_13&action=edit&section=new&header=Please%20fix%20Gadget-extraTabs.js", tabLabel = "Tab", tabDesc = "Please contact [[User:Technical_13]]", tabAfter = "";

function createTab(tabName, tabLocation, tabLabel, tabDesc, tabAfter){
	mw.util.addPortletLink(
		'p-namespaces',
		tabLocation,
		tabLabel,
		'ca-' + tabName,
		tabDesc,
		'',
		tabAfter 
	);
}

if(nsNum === -1){
	if(specialPageName === "ExpandTemplates"){
		nsNum = -13;
		isET = true;
		rawPageName = document.location.href.slice(document.location.href.indexOf("wpInput=%7B%7B")+14, document.location.href.indexOf("%0A"));
	} else if (specialPageName === "ComparePages" && typeof($('input#mw-input-page1').val().indexOf("Template:")) !== "undefined"){
		nsNum = -13;
		isDiff = true;
		rawPageName = $('input#mw-input-page1').val().substr($('input#mw-input-page1').val().indexOf("Template:")+9);
	}
}

if(nsNum === -13 || nsNum === 10 || nsNum === 11){
	if(rawPageName.indexOf('/sandbox') !== -1){
		rawPageName = rawPageName.slice(0, rawPageName.indexOf('/sandbox'));
		isSand = true;
	}
	if (rawPageName.indexOf('/testcases') !== -1) {
		rawPageName = rawPageName.slice(0, rawPageName.indexOf('/testcases'));
		isTest = true;
	}
	if (rawPageName.indexOf('/doc') !== -1) {
		rawPageName = rawPageName.slice(0, rawPageName.indexOf('/doc'));
		isDoc = true;
	}
	if(nsNum === 11) {
		isTalk = true;
	} else if(nsNum === 10){
		isPage = true;
	}
	var rawPage = artPath.replace('$1', 'Template:' + rawPageName);
	var talkPage = artPath.replace('$1', 'Template_talk:' + rawPageName);
	var sandbox = artPath.replace('$1', 'Template:' + rawPageName + '/sandbox');
	var sandTalk = artPath.replace('$1', 'Template_talk:' + rawPageName + '/sandbox');
	var testcases = artPath.replace('$1', 'Template:' + rawPageName + '/testcases');
	var testTalk = artPath.replace('$1', 'Template_talk:' + rawPageName + '/testcases');
	var documentation = artPath.replace('$1', 'Template:' + rawPageName + '/doc');
	var docTalk = artPath.replace('$1', 'Template_talk:' + rawPageName + '/doc');
	var sandDiff = artPath.replace('$1', 'Special:ComparePages/?page1=' + rawPage + '&page2=' + sandbox);
	var testExpand = fullScriptPath + '/index.php?title=Special:ExpandTemplates&wpContextTitle=&wpInput=%7B%7B' + rawPageName + '%0A%7C%201%20%3D%0A%7C%202%20%3D%0A%7C%203%20%3D%0A%7C%204%20%3D%0A%7C%205%20%3D%0A%7D%7D&wpRemoveComments=1&wpRemoveNowiki=1';
	$('#ca-nstab-template').find('a').attr('href', rawPage);
	$('#ca-talk').find('a').attr('href', talkPage);
	createTab('sandbox', sandbox, 'Sandbox', 'View the sandbox');
	createTab('testcases', testcases, 'Testcases', 'View the testcases');
/* sandbox talk page */
	if(isSand === true && isTalk === true){
		createTab('sandtalk', sandTalk, 'Talk', 'View the talk page for the sandbox', '#ca-test');
		$('#ca-sandtalk').addClass("selected");
		$('#ca-talk').removeClass("selected");
		if($('#ca-nstab-template.new')){
			$('#ca-nstab-template.new').removeClass('new');
			$('#ca-sand').attr('href', $('#ca-sand').attr('href') + '?action=edit&redlink=1').addClass('new');
		}
		if($('span.subpages')){
			$('#ca-talk').removeClass("new");
		} else {
			$('#ca-talk').addClass("new");
		} 
	}
/* testcases talk page */
	else if(isTest === true && isTalk === true){
		createTab('testTalk', testTalk, 'Talk', 'View the talk page for the testcases');
		$('#ca-talk').removeClass("selected");
		$('#ca-testtalk').addClass("selected");
		if($('#ca-nstab-template.new')){
			$('#ca-nstab-template.new').removeClass('new');
			$('#ca-test').attr('href', $('#ca-test').attr('href') + '?action=edit&redlink=1').addClass('new');
		}
		if($('span.subpages')){
			$('#ca-talk').removeClass("new");
		} else {
			$('#ca-talk').addClass("new");
		}
	}
/* sandbox page */
	else if(isSand === true){
		$('#ca-nstab-template').removeClass("selected");
		$('#ca-sand').addClass("selected");
		createTab('sandTalk', sandTalk, 'Talk', 'View the talk page for the sandbox');
		if($('#ca-talk.new')){
			$('#ca-talk.new').removeClass('new');
			$('#ca-sandTalk').attr('href', $('#ca-sandTalk').attr('href') + '?action=edit&redlink=1').addClass('new');
		}
		if($('span.subpages')){
			$('#ca-nstab-template').removeClass("new");
		} else {
			$('#ca-nstab-template').addClass("new");
		}
	}
/* testcases page */
	else if(isTest === true){
		$('#ca-nstab-template').removeClass("selected");
		$('#ca-test').addClass("selected");
		createTab('testTalk', testTalk, 'Talk', 'View the talk page for the testcases');
		if($('#ca-talk.new')){
			$('#ca-talk.new').removeClass('new');
			$('#ca-sandTalk').attr('href', $('#ca-sandTalk').attr('href') + '?action=edit&redlink=1').addClass('new');
		}
		if($('span.subpages')){
			$('#ca-nstab-template').removeClass("new");
		} else {
			$('#ca-nstab-template').addClass("new");
		}
	}
/* template or talk page */
	else if(isPage === true || isTalk === true){
		if($('#ca-nstab-template')){
			$('#ca-nstab-template').attr('href', $('#ca-nstab-template').attr('href') + '?action=edit&redlink=1');
		}
		if($('#ca-talk.new')){
			$('#ca-talk.new').attr('href', $('#ca-talk.new').attr('href') + '?action=edit&redlink=1');
		}
	}
// Create tabs before 'ca-nstab-special' for T: Tt:
}