User:MrMeAndMrMe/SimpleWPTab.js: Difference between revisions
Appearance
Content deleted Content added
MrMeAndMrMe (talk | contribs) ←Created page with '// [[stolen from some other guy // 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 = '//' + 'simple.wikipedia.org/wiki/' + mw.config.get('wgPageName'); // Set Engli...' |
MrMeAndMrMe (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
⚫ | |||
// [[stolen from some other guy |
|||
⚫ | |||
⚫ | |||
// Define "entabMainTab" variable before cloning it. |
|||
⚫ | |||
⚫ | |||
// Clone main page tab |
|||
⚫ | |||
// Construct URL for English Wikipedia |
|||
⚫ | |||
// Set English Wikipedia tab URL, text, and title |
|||
⚫ | |||
// Get sandbox existence status via Ajax |
|||
new mw.ForeignApi( 'https://simple.wikipedia.org/w/api.php' ).get( { |
|||
action: 'query', |
|||
titles: mw.config.get( 'wgPageName' ) |
|||
} ).done( function ( ret ) { |
|||
// Ajax function on data return: If 'missing' field is defined, page is missing, so add 'new' class to tab, which turns it red |
|||
if (Object.keys( ret.query.pages )[0] == '-1') entabTab.addClass( 'new' ); |
|||
⚫ | |||
$.ajax({ |
|||
⚫ | |||
⚫ | |||
dataType: "xml", |
|||
// ** Making tab red still doesn't work for some reason, haven't figured that out yet, |
|||
type: "GET", |
|||
// ** but the ajax url is correct as you can see if you navigate to it manually: |
|||
success:parseIt |
|||
⚫ | |||
⚫ | |||
function parseIt (xml){ |
|||
var missing = $(xml).find('page').attr('missing'); |
|||
if (typeof missing != "undefined") simpletabTab.addClass('new'); |
|||
} |
|||
⚫ |
Revision as of 00:54, 11 July 2024
var simpletabMainTab = $('#left-navigation li:not(.selected)').slice(0,1).css('opacity','0.9');
var simpletabTab = simpletabMainTab.clone(true).attr('id', simpletabMainTab.attr('id')+'-').css('opacity','0.9').removeClass('new');
var simpletabURL = 'http://' + 'simple.wikipedia.org/wiki/' + mw.config.get('wgPageName');
simpletabTab.find('a').attr('href', simpletabURL).empty().text('Simple').attr('title', "Navigate to this page on Simple Wikipedia");
$.ajax({
url:"http://simple.wikipedia.org/w/api.php?action=query&titles=" + encodeURIComponent(mw.config.get('wgPageName')) + "&format=xml",
dataType: "xml",
type: "GET",
success:parseIt
});
function parseIt (xml){
var missing = $(xml).find('page').attr('missing');
if (typeof missing != "undefined") simpletabTab.addClass('new');
}
simpletabTab.insertBefore($('#right-navigation li').slice(0,1));