Jump to content

User:MrMeAndMrMe/SimpleWPTab.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
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...'
 
No edit summary
Line 1: Line 1:
var simpletabMainTab = $('#left-navigation li:not(.selected)').slice(0,1).css('opacity','0.9');
// [[stolen from some other guy
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');
// Define "entabMainTab" variable before cloning it.
var entabMainTab = $('#left-navigation li:not(.selected)').slice(0,1).css('opacity','0.9');
simpletabTab.find('a').attr('href', simpletabURL).empty().text('Simple').attr('title', "Navigate to this page on Simple Wikipedia");
// 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 English Wikipedia tab URL, text, and title
entabTab.find('a').attr('href', entabURL).empty().text('Simple English').attr('title', "Navigate to this page on Simple English Wikipedia");
// 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({
entabTab.insertAfter($('#left-navigation li').slice(0,1));
url:"http://simple.wikipedia.org/w/api.php?action=query&titles=" + encodeURIComponent(mw.config.get('wgPageName')) + "&format=xml",
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
// ** http://en.wikipedia.org/w/api.php?action=query&titles=monkey&format=xml
});

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));

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));