User:Equazcion/test.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/test. |
// ** "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 was messed up
var speciestabURL = 'http://' + 'species.wikimedia.org/wiki/' + 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");
// ** URL needed tweaking here: " + '/WikiSpecies' " isn't required and was messing things up.
$.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