User:BryghtShadow/global.js

$( function {	'use strict';	const conf = mw.config.get( [ 'wgIsTestModeEnabled', 'isGamepedia', ] );

function foo { 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 polyfill { return mw.loader.using( [			'mediawiki.Uri',			'mediawiki.util',			'ext.fandom.ContentReview.legacyLoaders.js',		], function {			function getDependencies( articles ) {				const dependencies = articles.map( mw.util.wikiUrlencode )					.map( function( a ) { if ( conf.wgIsTestModeEnabled && /\.js$/i.test( a ) ) { return 'test:' + a;						} else { return a;						} } )					.filter( function( a ) { return mw.loader.getState( a ) === null; } );

dependencies.forEach( function( a ) {					mw.loader.register(a);				} );

return dependencies; }

function request( dependencies ) { const loadUrl = 'https://community.fandom.com/load.php', uri = new mw.Uri( loadUrl );

uri.extend( {					debug: 'false',					lang: 'en',					modules: dependencies.join( '|' ),					skin: 'fandomdesktop',				} );

return mw.loader.getScript( uri.toString ).catch( function {					dependencies.forEach( function( a ) { console.log( a + ': ' + mw.loader.getState( article ) ); } );				} );			}

function getArticles( obj ) { return obj.article ? [obj.article] : obj.articles; }

window.importArticles = function { const articles = Array.from( arguments ) .reduce( function( acc, obj ) {						return acc.concat( getArticles( obj ) );					}, [] ); const dependencies = getDependencies( articles ); if ( dependencies.length > 0) { return request( articles ); }			};			window.importArticle = window.importArticles; } );	}

if ( conf.isGamepedia || !window.importArticles ) { polyfill.then( foo ); } else { foo; } } );

$(function {	'use strict';

// https://stackoverflow.com/a/38882022 function waitForAddedNode(params) { new MutationObserver(function(mutations) {			var el = document.getElementById(params.id);			if (el) {				this.disconnect;				params.done(el);			}		}).observe(params.parent || document, {			subtree: !!params.recursive,			childList: true,		}); }	function addCodeEditorAccessKey($editform) { const $textbox = $('#wpTextbox1'); const accesskey = $textbox.attr('accesskey'); const targetNode = $editform[0]; const config = { subtree: true, attributeOldValue: true, };		const observer = new MutationObserver(function(mutations) {			mutations.forEach(function(mutation) { if (mutation.type === 'attributes' && mutation.attributeName==="class") { const target = mutation.target; if (target.id === 'wikiEditor-ui-toolbar') { const codeEditorEnabled = target.classList.contains('codeEditor-ui-toolbar'); if (codeEditorEnabled) { $('.ace_text-input').attr('accesskey', accesskey); $textbox.removeAttr('accesskey'); } else { $textbox.attr('accesskey', accesskey); }					}				}			});		});		observer.observe(targetNode, config); }	mw.hook('wikipage.editform').add(addCodeEditorAccessKey);

function addScribuntoAccessKey { // Jump to Scribunto console waitForAddedNode({			id: 'mw-scribunto-input',			parent: document.querySelector('#mw-scribunto-console'),			recursive: false,			done: function(el) {				console.log(el);				el.setAttribute('accesskey', '/');			}		}); }	if (mw.config.get('wgNamespaceNumber') === 828) { mw.hook('wikipage.editform').add(addScribuntoAccessKey); } });

$(function {	// Fix duplicate accesskey for Edit.	const editButton = $('.page-side-edit').first[0];	if (typeof editButton === 'undefined') return;	const accesskey = editButton.getAttribute('accesskey');	if (accesskey !== 'e') return;	const $accesskey = $('[accesskey="'+accesskey+'"]');	if ($accesskey.length === 1) return;	$accesskey.each(function(_, btn) { if (btn === editButton) return; btn.removeAttribute('id'); btn.removeAttribute('accesskey'); }); });

// Default expand footer categories. $(function {	const footerCategories = $('.page-footer__categories');	if (footerCategories.length === 0) { return; }	footerCategories.removeClass('wds-is-collapsed'); });

// Hide notification that keeps persistently popping up... $(function {	const messages = [		"As we move into the future of Fandom, we have a new logo, new colors, and new desktop and mobile experiences. Learn more about the future of Fandom here.",	];	$('.wds-banner-notification.wds-message.notify').each(function(_, banner) { const text = $(banner).text.trim; if (messages.includes(text)) { $(banner).find('.wds-banner-notification__close > .wds-icon.wds-icon-tiny').click; }	}); });

// Add Special:TrackingCategories backlink to tracking categories. $(function {	"use strict";	const conf = mw.config.get([ 'wgContentLanguage', 'wgTitle', 'wgCanonicalNamespace', 'wgAction', 'wgArticlePath', ]);	const TARGET_SELECTOR = 'page-header__page-subtitle';	const TARGET_SELECTOR_PARENT = 'page-header__main';	const BACKLINK_PAGE = 'Special:TrackingCategories';	const BACKLINK_TITLE = 'Tracking categories';	const BACKLINK_URL = conf.wgArticlePath.replace('$1', BACKLINK_PAGE);	if ( conf.wgCanonicalNamespace !== 'Category' || 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(messages) { if (!messages) { // This shouldn't happen... console.debug("STC: Could not find any messages...?"); return; }		if (!Object.values(messages).includes(conf.wgTitle)) { // Not a tracking category. console.debug('STC: '+conf.wgTitle+' is not a tracking category.'); return; }		// 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' ).then( function {		return new mw.Api.getMessages( ALLMESSAGES, { amlang: conf.wgContentLanguage, });	}).done(addBacklink); });