Jump to content

User:TheTVExpert/scriptDocumentationTabs.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.
$(document).ready(function (){
if(mw.config.get('wgCanonicalNamespace')==='User' && mw.config.get('wgAction') !== 'history' && !document.getElementById("wikiPreview")) {
var page = mw.config.get('wgPageName');
var js = page.substr(page.length - 3);
if(js==".js") {
	page = page.slice(0,-3);
	new mw.Api().get( {
     action: "query",
     titles: [ page ],
 } ).then( function( ret ) {
     $.each( ret.query.pages, function() {
         if ( this.missing !== "" ) {
	var list = document.createElement("LI");
	var link = document.createElement("A");
	link.innerHTML = "Documentation";
	link.href = "/wiki/" + page;
	link.title = "View documentation";
	list.appendChild(link);
	var talk = document.getElementById("ca-talk");
	talk.parentNode.insertBefore(list, talk.nextSibling);
         }
     } );
 }, function( error ) {
     
 } );
} else {
	page = page + ".js";
	new mw.Api().get( {
     action: "query",
     titles: [ page ],
 } ).then( function( ret ) {
     $.each( ret.query.pages, function() {
         if ( this.missing !== "" ) {
         	var list = document.createElement("LI");
			var link = document.createElement("A");
			link.innerHTML = "Script";
            link.href = "/wiki/" + page;
            link.title = "View script";
            list.appendChild(link);
			var talk = document.getElementById("ca-talk");
			talk.parentNode.insertBefore(list, talk.nextSibling);
         }
     } );
 }, function( error ) {
     
 } );
}
}
});