User:Equazcion/SandTab.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:Equazcion/SandTab. |
if (mw.config.get('wgNamespaceNumber') == 10) { // Only if we're in Template: space
// Grab main page tab
var sandtabMainTab = $('#left-navigation li:not(.selected)').slice(0,1).css('opacity','0.9');
// Clone main page tab
var sandtabTab = sandtabMainTab.clone(true).attr('id', sandtabMainTab.attr('id')+'-').css('opacity','0.9').removeClass('new');
// Construct URL
var sandtabURL = 'http://' + wgPageContentLanguage + '.' + wgNoticeProject + '.org/w/index.php?title=' + wgPageName + '/sandbox';
// Set sandbox tab URL, text, and title
sandtabTab.find('a').attr('href', sandtabURL).empty().text('Sandbox').attr('title', "Navigate to this page's sandbox");
// Get sandbox existence status via Ajax
$.ajax({
url:"http://en.wikipedia.org/w/api.php?action=query&titles=" + encodeURIComponent(wgPageName + '/sandbox') + "&format=xml",
dataType: "xml",
type: "GET",
success:parseIt
});
sandtabTab.insertBefore($('#right-navigation li').slice(0,1));
}
// Ajax function on data return: If 'missing' field is defined, page is missing, so add 'new' class to tab, which turns it red
function parseIt (xml){
var missing = $(xml).find('page').attr('missing');
if (typeof missing != "undefined") sandtabTab.addClass('new');
}