User:Majr/docTabs.js

$( function { 'use strict';

var page = mw.config.get( 'wgTitle' ), title = page.replace( '/doc', '' );

$( '#p-namespaces li:last' ).after( ' Doc ' +									' Doc talk ' );

setTimeout( function {	mw.loader.using( ['jquery.collapsibleTabs', 'ext.vector.collapsibleTabs'], function { $.collapsibleTabs.handleResize; } ); }, 1000 );

if ( page.indexOf( '/doc' ) > -1 ) { $( '#ca-nstab-template' ).removeClass( 'selected' ).find( 'a' ).prop( 'href', function {		return this.href.replace( '/doc', '' );	} ); $( '#ca-talk' ).removeClass( 'selected' ).find( 'a' ).prop( 'href', function {		return this.href.replace( '/doc', '' );	} ); if ( mw.config.get( 'wgNamespaceNumber' ) === 10 ) { $( '#ca-doc' ).addClass( 'selected' ); } else { $( '#ca-doc-talk' ).addClass( 'selected' ); } }

new mw.Api.get( {	action: 'query',	prop: 'info',	titles: 'Template:' + title + '|Template talk:' + title + '|Template:' + title + '/doc|Template talk:' + title + '/doc' } ).done( function( data ) {	var nameToId = {};	nameToId['Template:' + title] = '#ca-nstab-template';	nameToId['Template talk:' + title] = '#ca-talk';	nameToId['Template:' + title + '/doc'] = '#ca-doc';	nameToId['Template talk:' + title + '/doc'] = '#ca-doc-talk';

$.each( data.query.pages, function {		var id = nameToId[this.title];		if ( this.hasOwnProperty( 'missing' ) ) {			if ( !$( id ).hasClass( 'new' ) ) {				$( id ).addClass( 'new' ).find( 'a' ).prop( 'href', function { return this.href.replace( /gamepedia\.com\/(.+)/, 'gamepedia.com/index.php?title=$1&action=edit&redlink=1' ); } );			}		} else {			$( id ).removeClass( 'new' ).find( 'a' ).prop( 'href', function { return this.href.replace( /index\.php\?title=([^&]+)&action=edit&redlink=1/, '$1' ); } );		}	} ); } ).fail( function( error ) { console.error( error ); } );

} );