Jump to content

User:TyphoonAmpil/Simpletab.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var simpletabMainTab = $('#left-navigation li:not(.selected)').slice(0,1).css('opacity','0.9');
// Simple wiki //
var simpletabTab = simpletabMainTab.clone(true).attr('id', simpletabMainTab.attr('id')+'-').css('opacity','0.9').removeClass('new');

var simpletabURL = '//' + 'simple.wikipedia.org/wiki/' + mw.config.get('wgPageName');

simpletabTab.find('a').attr('href', simpletabURL).empty().text('SimpleWiki').attr('title', "Navigate to this page on Simple English Wikipedia");

// API //
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') simpletabTab.addClass( 'new' );
} );

simpletabTab.insertAfter($('#left-navigation li').slice(0,1));