User:Djsasso/enWPTab.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Define "entabMainTab" variable before cloning it.
var entabMainTab = $('#left-navigation li:not(.selected)').slice(0,1).css('opacity','0.9');
// Clone main page tab
var entabTab = entabMainTab.clone(true).attr('id', entabMainTab.attr('id') '-').css('opacity','0.9').removeClass('new');
// Construct URL for English Wikipedia
var entabURL = '//' 'en.wikipedia.org/wiki/' mw.config.get('wgPageName');
// Set English Wikipedia tab URL, text, and title
entabTab.find('a').attr('href', entabURL).empty().text('English').attr('title', "Navigate to this page on English Wikipedia");
// Get sandbox existence status via Ajax
$.ajax({
url:"//en.wikipedia.org/w/api.php?action=query&titles=" encodeURIComponent(mw.config.get('wgPageName')) "&format=xml",
dataType: "xml",
type: "GET",
success:parseIt
});
// 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") entabTab.addClass('new');
}
entabTab.insertBefore($('#right-navigation li').slice(0,1));
// ** Making tab red still doesn't work for some reason, haven't figured that out yet,
// ** but the ajax url is correct as you can see if you navigate to it manually:
// ** http://en.wikipedia.org/w/api.php?action=query&titles=monkey&format=xml