User:BryghtShadow/global.js

importArticles( {	type: 'script',	articles: [		// Regular scripts.		'u:dev:MediaWiki:ImportJSPage/code.js',		'u:dev:MediaWiki:ThemeToggler.js'	] } );

var cfg = mw.config.get( [	'wgAction',	'wgCanonicalSpecialPageName',	'wgContentLanguage',	'wgNamespaceNumber',	'wgUserLanguage',	'wgTitle' ] );

/** * Helper function to load system messages **/ function getMessages( a ) { return mw.loader.using( "mediawiki.api" ).then( function {		var e = new mw.Api,			t = cfg.wgContentLanguage;		return t !== cfg.wgUserLanguage			? e.getMessages( a, { amlang: t } )			: e.loadMessagesIfMissing( a ).then( function  { return a.reduce( function ( e, t ) {					return e[ t ] = mw.message( t ).plain, e				}, {} ) } )	} ) }

/** * Editform access keys. **/ mw.hook( "wikipage.editform" ).add( function ( $ef ) {	// mutation observer	function n( o ) {		var c = o.id ? function ( t ) {			var e = document.getElementById( o.id );			e && o.ok( e, t )		} : function ( t ) {			var e = document.getElementsByClassName( o.cl )[ 0 ];			e && o.ok( e, t )		},		t = new MutationObserver( function ( t, e ) { c( e ) } ).observe( o.p || document, { subtree: !!o.st || !o.p,			childList: 1 } );		return c, t	}	// add accesskey to CodeEditor	n( { p: $ef[ 0 ], cl: "wikiEditor-ui-text", st: 1, ok: function ( t, e ) { e && e.disconnect, // add accesskey to Ace Editor n( {				p: t,				cl: "ace_text-input",				ok: function ( t, e ) {					t.setAttribute( "accesskey", "," )				}			} ), // add accesskey when CodeMirror's syntax highlight is enabled n( {				p: t,				cl: "noime",				ok: function ( t, e ) {					t.setAttribute( "accesskey", "," )				}			} ) }	} ),	// add accesskey to Scribunto console.	828 === cfg.wgNamespaceNumber && n( { p: document.getElementById( "mw-scribunto-console" ), id: "mw-scribunto-input", ok: function ( t, e ) { e && e.disconnect, t.setAttribute( "accesskey", "/" ) }	} ) } );

/** * Add Special:TrackingCategories backlink to tracking categories. **/ mw.loader.using( "mediawiki.Title", function {	var e, r, t, a,		n = "page-header__page-subtitle",		g = new mw.Title( "TrackingCategories", -1 ).getUrl;	14 === cfg.wgNamespaceNumber &&	/view|history/.test( cfg.wgAction ) &&	!$( "." + n + ' a[href="' + g + '"]' ).length &&	( e = "broken-file-category|cite-tracking-category-cite-error|deprecated-self-close-category|duplicate-args-category|expansion-depth-exceeded-category|expensive-parserfunction-category|hidden-category-category|index-category|magiclink-tracking-isbn|math-tracking-category-error|math-tracking-category-render-error|node-count-exceeded-category|noindex-category|post-expand-template-argument-category|post-expand-template-inclusion-category|restricted-displaytitle-ignored|scribunto-common-error-category|scribunto-module-with-errors-category|syntaxhighlight-error-category|template-loop-category|timeline-tracking-category".split( "|" ), r = "trackingcategories", e.push( r ), getMessages( e ).then( function( e ) {			Object.values( e ).includes( cfg.wgTitle ) &&			( t = e[ r ], ( e = ( a = $( "." + n ) ).length ) || ( a = $( " ", { class: n } ), $( ".page-header__main" ).append( a ) ), a.prepend( [					"&lt; ",					$( "", { href: g,						title: t,						text: t					} ),					e && " | "				] ) )		} )	) } );

/** * Add rail to pages that don't have one **/ $( function {	if ( $( '.page.has-right-rail' ).length ) return;

function getModuleName( name ) { return mw.loader.getModuleNames.find( function ( s ) {			return s.startsWith( name );		} ); }	var PreferencesHelper = getModuleName( 'PreferencesHelper' ), tooltips = getModuleName( 'tooltips' );

mw.loader.using( [		'skin.fandomdesktop.rail.css',		PreferencesHelper,		tooltips,	] ).then( function {		var ui, wds;		var rail = {			loading: [				'dorui',				'wds',			],			onload: function ( k, v ) {				switch ( k ) {					case 'dorui':						ui = v;						break;					case 'wds':						wds = v;						break;				}				var i = this.loading.indexOf( k );				if ( i === -1 ) throw new Error( 'Unregistered dependency loaded: ' + k );				this.loading.splice( i, 1 );				if ( this.loading.length ) return;				this.init;			},			preload: function  {				PreferencesHelper = mw.loader.require( PreferencesHelper );				tooltips = mw.loader.require( tooltips );

importArticles( {					type: 'script',					articles: [						'u:dev:MediaWiki:Dorui.js',						'u:dev:MediaWiki:WDSIcons/code.js'					]				} ); mw.hook( 'doru.ui' ).add( this.onload.bind( this, 'dorui' ) ); mw.hook( 'dev.wds' ).add( this.onload.bind( this, 'wds' ) ); },			init: function { var v = mw.user.options.values.rightrailvisible === 'visible', e = ui.button( {					class: 'right-rail-toggle',					'data-wds-tooltip': v ? 'Hide' : 'Show',					'data-wds-tooltip-position': 'bottom',					child: wds.icon( 'menu-control-tiny' ),				} ), r = ui.aside( {					classes: {						'page__right-rail': true,						'is-rail-hidden': !v					},					children: [						e,						ui.div( { class: 'right-rail-wrapper WikiaRail', children: [ ui.div( {									id: 'rail-boxad-wrapper'								} ), ui.div( {									id: 'WikiaRail'								} ), ]						} )					]				} );				$( '.page__main' ) .after( r ) .parent .addClass( 'has-right-rail' )

e && r && e.addEventListener( 'click', function {					var i = r.classList.toggle( 'is-rail-hidden' );					e.dataset.wdsTooltip = mw.message( i ? 'show' : 'hide' ).text,					PreferencesHelper.setPreference( 'rightrailvisible', i ? 'hidden' : 'visible' ),					setTimeout( function { var e = new Event( 'FandomDesktopContentSize' ) window.dispatchEvent( e ) }, 300 )				} )

tooltips.handleAllElementsWithTooltip

$.when( this.loadRail ).done( function ( e ) {					$( '.right-rail-wrapper' ).append( e ),					$( '#WikiaRail' ).addClass( 'is-ready' ).trigger( 'afterLoad.rail' );				} ) },			loadRail: function { var e = $.Deferred, t = ui.div( {					class: 'sticky-modules-wrapper',					child: ui.section( { id: 'p-tb', class: 'rail-module page-tools-module', children: [ ui.h2( {								class: 'rail-module__header has-icon',								text: 'Page Tools'							} ), ui.ul( {								class: 'rail-module__list is-condensed-list',								children: $( 'ul.page__hidden-page-tools > li' ).unwrap							} ), ]					} )				} )				e.resolve( t ) return e.promise }		};		rail.preload; } ); } );

// Add toggle to hide empty and disabled tracking categories $( function {	'use strict';	var buttonId = 'toggle-empty-tracking-categories';	if ( cfg.wgCanonicalSpecialPageName !== 'TrackingCategories' || $( '#' + buttonId ).length ) {		return;	}

$( '#mw-trackingcategories-table > tbody > tr' ).each( function ( _, tr ) {		var td = $( tr ).find( 'td.mw-trackingcategories-name' ),			emptySpans = td.find( '> span:contains("(empty)")' ),			allSpans = td.find( '> span' );		if ( td.text === 'Category is disabled' || emptySpans.length === allSpans.length ) {			$( tr ).addClass( 'category-is-empty' );		}	} );

mw.hook( 'dev.wds' ).add( function ( wds ) {		var styles = mw.util.addCSS( '.category-is-empty { display: none; }' ),			button = $( ' ' )				.attr( 'id', buttonId )				.addClass( 'wds-button empty-categories-toggle' )				.append( wds.icon( 'eye-small' ) );		button.click( function ( e ) { styles.disabled = !styles.disabled; var name = styles.disabled ? 'eye-small' : 'eye-crossed-small'; $( e.currentTarget ).html( wds.icon( name ) ); } );		$( '#firstHeading' ).append( button );	} ); importArticles( {		type: 'script',		articles: [			'u:dev:MediaWiki:WDSIcons/code.js'		]	} ); } );

// Temp fix for media in classic categories. $( function {	'use strict';	if ( cfg.wgNamespaceNumber !== 14 || $( '.wikia-gallery-item .gallerytext' ).length > 0 ) {		return;	}

mw.loader.using( [ 'mediawiki.util', 'mediawiki.Title' ], function {		const re = /^(.+?) \((\d+[^]+)\)$/;		mw.util.addCSS( '.galleryfilename { display: block; } ' );		mw.util.addCSS( '.galleryfilename-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }' );		$( '.wikia-gallery-item' ).each( function ( _, item ) { var anchor = $( '.thumb .image', item ), m = re.exec( anchor.attr( 'title' ) ), name = m[1], size = m[2], filename = mw.Title.newFromFileName( name ), galleryText = $( ' ' ) .addClass( 'gallerytext' ), galleryFilename = $( '' ) .addClass( 'galleryfilename galleryfilename-truncate' ) .attr( 'href', anchor.attr( 'href' ) ) .attr( 'title', filename.getPrefixedText ) .text( name ); galleryText.append( [ galleryFilename, size ] ); $( item ).append( galleryText ); } );	} ); } );