User:Grolltech/wikispeciestab.js

// This code lifted from User_talk:Equazcion

// ** "speciestabMainTab" is a variable you need to define before you clone it. var speciestabMainTab = $('#left-navigation li:not(.selected)').slice(0,1).css('opacity','0.9'); // Clone main page tab var speciestabTab = speciestabMainTab.clone(true).attr('id', speciestabMainTab.attr('id')+'-').css('opacity','0.9').removeClass('new'); // ** URL for wikispecies var speciestabURL = 'http://' + 'species.wikimedia.org/wiki/' + mw.config.get('wgPageName'); // Set WikiSpecies tab URL, text, and title speciestabTab.find('a').attr('href', speciestabURL).empty.text('WikiSpecies').attr('title', "Navigate to this page on WikiSpecies"); $.ajax({  url:"http://species.wikimedia.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") speciestabTab.addClass('new'); } speciestabTab.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://species.wikimedia.org/w/api.php?action=query&titles=monkey&format=xml