User:Technical 13/SandBox/Gadget-extraTabs.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:Technical 13/SandBox/Gadget-extraTabs. |
var nsNum = mw.config.get('wgNamespaceNumber');
if(nsNum === 10 || nsNum === 11){
var isPage = false, isTalk = false, isSand = false, isTest = false;
console.log("Initializing: Page: %s\tTalk: %s\tSand: %s\tTest: %s", isPage, isTalk, isSand, isTest);
var rawPageName = mw.config.get('wgTitle');
console.log("Initializing: rawPageName: %s", rawPageName);
if(rawPageName.indexOf('/sandbox') !== -1){
rawPageName = rawPageName.slice(0, rawPageName.indexOf('/sandbox'));
isSand = true;
console.log("rawPageName: %s\nPage: %s\tTalk: %s\tSand: %s\tTest: %s", rawPageName, isPage, isTalk, isSand, isTest);
}
if (rawPageName.indexOf('/testcases') !== -1) {
rawPageName = rawPageName.slice(0, rawPageName.indexOf('/testcases'));
isTest = true;
console.log("rawPageName: %s\nPage: %s\tTalk: %s\tSand: %s\tTest: %s", rawPageName, isPage, isTalk, isSand, isTest);
}
if(nsNum === 11) {
isTalk = true;
console.log("Talk? Page: %s\tTalk: %s\tSand: %s\tTest: %s", isPage, isTalk, isSand, isTest);
} else if(nsNum === 10){
isPage = true;
console.log("Template? Page: %s\tTalk: %s\tSand: %s\tTest: %s", isPage, isTalk, isSand, isTest);
}
var rawPage = mw.config.get('wgArticlePath').replace('$1', 'Template:' + rawPageName);
console.log("rawPage: %s", rawPage);
var talkPage = mw.config.get('wgArticlePath').replace('$1', 'Template_talk:' + rawPageName);
console.log("talkPage: %s", talkPage);
var sandbox = mw.config.get('wgArticlePath').replace('$1', 'Template:' + rawPageName + '/sandbox');
console.log("sandbox: %s", sandbox);
var sandTalk = mw.config.get('wgArticlePath').replace('$1', 'Template_talk:' + rawPageName + '/sandbox');
console.log("sandTalk: %s", sandTalk);
var testcases = mw.config.get('wgArticlePath').replace('$1', 'Template:' + rawPageName + '/testcases');
console.log("testcases: %s", testcases);
var testTalk = mw.config.get('wgArticlePath').replace('$1', 'Template_talk:' + rawPageName + '/testcases');
console.log("testTalk: %s", testTalk);
$('#ca-nstab-template').attr('href', rawPage);
console.log("Set #ca-nstab-template href attr to %s", rawPage);
$('#ca-talk').attr('href', talkPage);
console.log("Set #ca-talk href attr to %s", talkPage);
mw.util.addPortletLink('p-namespaces', sandbox, 'Sandbox', 'ca-sand', 'View the sandbox');
console.log("Created #ca-sand with href attr of %s", sandbox);
mw.util.addPortletLink('p-namespaces', testcases, 'Testcases', 'ca-test', 'View the testcases');
console.log("Created #ca-test with href attr of %s", testcases);
if(isSand === true && isTalk === true){
$('#ca-nstab-template').removeClass("selected");
mw.util.addPortletLink('p-namespaces', sandTalk, 'Talk', 'ca-sandtalk', 'View the talk page for the sandbox', '', '#ca-test');
console.log("Created #ca-sandtalk with href attr of %s", sandTalk);
$('#ca-sandtalk').addClass("selected");
} else if(isTest === true && isTalk === true){
$('#ca-nstab-template').removeClass("selected");
mw.util.addPortletLink('p-namespaces', testTalk, 'Talk', 'ca-testtalk', 'View the talk page for the testcases');
console.log("Created #ca-testtalk with href attr of %s", testTalk);
$('#ca-testtalk').addClass("selected");
} else if(isSand === true){
$('#ca-nstab-template').removeClass("selected");
$('#ca-sand').addClass("selected");
mw.util.addPortletLink('p-namespaces', sandTalk, 'Talk', 'ca-sandtalk', 'View the talk page for the sandbox', '', '#ca-test');
console.log("Created #ca-sandtalk with href attr of %s", sandTalk);
} else if(isTest === true){
$('#ca-nstab-template').removeClass("selected");
$('#ca-test').addClass("selected");
mw.util.addPortletLink('p-namespaces', testTalk, 'Talk', 'ca-testtalk', 'View the talk page for the testcases');
console.log("Created #ca-testtalk with href attr of %s", testTalk);
}
}