User:BryghtShadow/global.js

$( function {	'use strict';	importArticles( { type: 'script', articles: [ // Scripts for doing Vanguard work. 'u:community:MediaWiki:Van-RedirectCategories.js', 'u:dev:MediaWiki:ShowWROnToolbar.js', 'u:dev:MediaWiki:VanguardTools.js', // Regular scripts. 'u:dev:MediaWiki:ImportJSPage/code.js', 'u:dev:MediaWiki:ThemeToggler.js', ]	} ); } );

$( function {	'use strict';	mw.hook( 'wikipage.editform' ).add( function ( $editform ) { // add accesskey to CodeEditor. new MutationObserver( function {			var p = document.getElementsByClassName( 'wikiEditor-ui-text' )[ 0 ];			if ( p ) {				this.disconnect;				new MutationObserver( function  { var e = document.getElementsByClassName( 'ace_text-input' )[ 0 ]; if ( e ) { e.setAttribute( 'accesskey', ',' ); }				} ).observe( p, { childList: true } );			}		} ).observe( $editform[ 0 ], { subtree: true, childList: true } ); // add accesskey to Scribunto console. if ( mw.config.get( 'wgNamespaceNumber' ) === 828 ) { var p = document.getElementById( 'mw-scribunto-console' ); new MutationObserver( function {				var e = document.getElementById( 'mw-scribunto-input' );				if ( e ) {					this.disconnect;					e.setAttribute( 'accesskey', '/' );				}			} ).observe( p, { childList: true } ); }	} ); } );

// Add Special:TrackingCategories backlink to tracking categories. $( function {	"use strict";	const conf = mw.config.get( [ 'wgAction', 'wgArticlePath', 'wgContentLanguage', 'wgUserLanguage', 'wgNamespaceNumber', 'wgTitle', ] );	const TARGET_SELECTOR = 'page-header__page-subtitle',		TARGET_SELECTOR_PARENT = 'page-header__main',		BACKLINK_PAGE = 'Special:TrackingCategories',		BACKLINK_TITLE = 'Tracking categories',		BACKLINK_URL = conf.wgArticlePath.replace( '$1', BACKLINK_PAGE );	if ( conf.wgNamespaceNumber !== 14 || conf.wgAction !== 'view' && conf.wgAction !== 'history' || $( '.' + TARGET_SELECTOR + ' a[href="' + BACKLINK_URL + '"]' ).length > 0 ) {		return;	}

const ALLMESSAGES = [ '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', ];	function addBacklink { // Construct backlink HTML link var backlink = '&lt; ' + mw.html.element( 'a', {			href: BACKLINK_URL,			title: BACKLINK_TITLE,		}, BACKLINK_TITLE );

// Page subtitle const target = '.' + TARGET_SELECTOR;

// If subtitle doesn't exist, create subtitle first if ( $( target ).length === 0) { $( '.' + TARGET_SELECTOR_PARENT ).append(				mw.html.element( 'div', { class: TARGET_SELECTOR, } )			);		} else { backlink += ' | '; }

$( target ).prepend( backlink ); }

mw.loader.using( [ 'mediawiki.api' ], function {		var api = new mw.Api;		var resp;		if ( conf.wgContentLanguage === conf.wgUserLanguage ) {			resp = api.loadMessagesIfMissing( ALLMESSAGES ).then( function  { return ALLMESSAGES.filter( function ( key ) {					var msg = mw.message( key );					return msg.exists && msg.plain === conf.wgTitle;				} ); } );		} else {			resp = api.getMessages( ALLMESSAGES, { amlang: conf.wgContentLanguage, } ).then( function ( messages ) { return ALLMESSAGES.filter( function ( key ) {					var msg = messages[ key ];					return typeof msg !== 'undefined' && msg === conf.wgTitle;				} ); } );		}		resp.then( function ( found ) { if ( found.length === 1 ) { addBacklink; }		} );	} ); } );

// Add toggle to hide empty and disabled tracking categories $( function {	'use strict';	var buttonId = 'toggle-empty-tracking-categories';	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'TrackingCategories' || $( '#' + buttonId ).length > 0 ) {		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 ( mw.config.get( '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 ); } );	} ); } );