User:BryghtShadow/global.js

importArticles( {	type: 'script',	articles: [		// Regular scripts.		'u:dev:MediaWiki:HideEmptyTrackingCategories.js',		'u:dev:MediaWiki:ImportJSPage/code.js',		'u:dev:MediaWiki:MassNullEdit/code.js',		'u:dev:MediaWiki:ModulesLinkToModules.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				}, {} ) } )	} ) }

/** Restore rail for pages that do not have a rail */ mw.loader.using([	'skin.fandomdesktop.rail.css', ]).then(function {	function addRail {		if (document.querySelector('.page.has-right-rail')) return;

var button = document.createElement('button'); button.className = "right-rail-toggle"; button.innerHTML = ' ';

var boxad = document.createElement('div'); boxad.id = 'rail-boxad-wrapper';

var rail = document.createElement('div'); rail.id = 'WikiaRail';

var railWrapper = document.createElement('div'); railWrapper.className = "right-rail-wrapper WikiaRail"; railWrapper.append(boxad, rail);

var aside = document.createElement('aside'); aside.className = "page__right-rail"; var visible = mw.user.options.get('rightrailvisible') === 'visible'; aside.classList.toggle('is-rail-hidden', !visible); aside.append(button, railWrapper);

var main = document.querySelector('main.page__main'); main.after(aside); main.parentElement.classList.add('has-right-rail'); mw.loader.load([			'skin.fandomdesktop.rail.toggle.js',			// 'skin.fandomdesktop.rail.lazyRail.js'		]); }	function loadPageTools { if (document.getElementById('p-tb')) return;

rail = document.createElement('div'); rail.className = 'sticky-modules-wrapper';

var section = document.createElement('section'); section.className = "rail-module page-tools-module"; section.id = "p-tb";

var h2 = document.createElement('h2'); h2.className = "rail-module__header has-icon"; h2.textContent = 'Page Tools';

var tools = document.querySelector('ul.page__hidden-page-tools'); tools.className = 'rail-module__list is-condensed-list';

section.append(h2, tools); rail.append(section); $(".right-rail-wrapper").append(rail); $("#WikiaRail").addClass("is-ready").trigger("afterLoad.rail"); }

addRail; loadPageTools; });

/** Restore link to Cargo's pagevalues **/ (function {	var id = 't-cargopagevalueslink';	if (!mw.config.get('wgCargoWeekDays') || mw.config.get('wgNamespaceNumber') === -1 || document.getElementById(id)) {		return;	}

function addLink { mw.loader.using(['mediawiki.util'], function {			mw.util.addPortletLink( 'p-tb', new URL(location.href).pathname + '?action=pagevalues', 'Page values', id //, [tooltip], [accesskey], [nextnode] )		})	}

if (document.getElementById('p-tb')) { addLink; } else { $("#WikiaRail").on('afterLoad.rail', addLink); }

});

/* * Add line numbers to `.mw-highlight-lines` where length exceeds 100 kB */ mw.hook('wikipage.content').add(function ($content) {	$('.mw-highlight.mw-highlight-lines pre').each(function (_, pre) { if ($('span', pre).length) return; var text = $(pre).text.trim; if (text.length <= 102400) return; $(pre).empty.append(text.split('\n').map(function (line, i) { var n = i + 1; return $(' ', { id: 'L-' + n }).append([				$('', { href: '#L-' + n }).append( $(' ', { class: 'linenos', 'data-line': n }) ),				line + '\n'			]); }));	}); }); /** * 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 && " | "				] ) )		} )	) } );

// 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 ); } );	} ); } );