User:Rail/global.js

/** * Global scripts divided into modules * @author Rail * * Main modules: * - snippets      | Small code scippets run on various pages * - importDevCodes | Import codes from Dev Wiki * * Helper modules: * - conf            | Hold wiki meta configuration * - msg           | Simple i18n logic * - isDarkWiki    | Determine whther wiki is dark or light themed * - init          | Run other modules, hold scripts configuration */ ;( function( mw, window ) {	'use strict';

// Killswitch if ( mw.util.getParamValue( 'noGlobalJS' ) === '1' ) { return; }

// Prevent double loading if ( window['4F0A95F9A3AE15C99DBF32CA3FC0CBC8E1141B7D43DDF99FFE46EB6D76C0BBA8'] ) { return console.warn( '[UCP Global JS] Already loaded' ); }	window['4F0A95F9A3AE15C99DBF32CA3FC0CBC8E1141B7D43DDF99FFE46EB6D76C0BBA8'] = true;

var self = {};

self.conf = mw.config.get( [		'wgContentLanguage',		'wgUserLanguage',		'wgAction',		'wgNamespaceNumber',		'wgTitle',		'wgCityId'	] );

self.locales = { en: { // English (en) 'summary-housekeeping': 'Housekeeping', 'summary-vandalism': 'Vandalism', 'summary-spam': 'Spam', 'summary-tou': 'Violation of Terms of Use', 'analytics': 'ANA', 'announcements': 'ANN', 'api-sandbox': 'API', 'interwiki-edit': 'IE', 'prefix-index': 'PI' },		pl: { // polski (pl) 'summary-housekeeping': 'Porządki', 'summary-vandalism': 'Wandalizm', 'summary-spam': 'Spam', 'summary-tou': 'Naruszenie Zasad Użytkowania' }	};

self.msg = function( msg, lang ) { function getLanguage { var language;

if ( lang ) { language = ( lang === 'content'					? self.conf.wgContentLanguage					: lang				); } else { language = self.conf.wgUserLanguage; }

return language; }

/**		 * Replacement for `jQuery.fn.extend` method * https://stackoverflow.com/a/38777298 */		function extend( defaults, options ) { var prop, extended = {};

for ( prop in defaults ) { if ( Object.prototype.hasOwnProperty.call( defaults, prop ) ) { extended[prop] = defaults[prop]; }			}			for ( prop in options ) { if ( Object.prototype.hasOwnProperty.call( options, prop ) ) { extended[prop] = options[prop]; }			}

return extended; }

function getString { // Use English message as a fallback if noting else is available const string = extend(				self.locales.en,				self.locales[getLanguage]			);

return string[msg]; }

return getString; };

self.snippets = function { const userToolbar = document.querySelector( '#WikiaBarWrapper .tools' );

function onToolbarLoaded( callback ) { const interval = setInterval( function {				if ( !!userToolbar ) {					clearInterval( interval );					callback;				}			}, 500 ); }

function createToolLinks( tools ) { if ( !userToolbar ) return;

const toolsMenu = document.getElementById( 'my-tools-menu' );

tools.forEach( function( tool ) {				const element = document.createElement( 'li' );				const link = document.createElement( 'a' );

element.classList.add( 'overflow' ); element.setAttribute( 'id', tool.id );

link.setAttribute( 'href', tool.url ); link.innerText = self.msg( tool.id );

element.appendChild( link );

if ( tool.inDropdown === false ) { userToolbar.prepend( element ); } else { toolsMenu.appendChild( element ); }			} );		}

onToolbarLoaded( function {			createToolLinks( [ {					id: 'announcements', url: mw.util.getUrl( 'Special:Announcements' ) },				{					id: 'analytics', url: mw.util.getUrl( 'Special:Analytics' ) },				{					id: 'api-sandbox', url: mw.util.getUrl( 'Special:ApiSandbox' ) },				{					id: 'prefix-index', url: mw.util.getUrl( 'Special:PrefixIndex', {						prefix: self.conf.wgTitle,						namespace: self.conf.wgNamespaceNumber					} ), inDropdown: false },				{					id: 'interwiki-edit', url: 'https://community.fandom.com/wiki/Special:InterwikiEdit?action=Edit+wiki&wikia_id=' + self.conf.wgCityId, inDropdown: false }			] );		} );

const deleteReason = document.getElementById( 'wpReason' ); if ( self.conf.wgAction === 'delete' && deleteReason ) { deleteReason.value = self.msg( 'summary-vandalism', 'content' ); }

if ( mw.util.getParamValue( 'so' ) ) { window.history.replaceState( {}, , window.location.href.replace( '?so=search',  ) ); }	};

self.isDarkWiki = function { const isFDDarkTheme = document.body.classList.contains( 'theme-fandomdesktop-dark' ); return isFDDarkTheme; };

// Import Dev Wiki codes self.importDevCodes = function { function getCodePages { return [ 'MediaWiki:SyntaxHighlight.js', 'MediaWiki:FastDelete/code.js', 'MediaWiki:ThemeToggler.js', 'MediaWiki:RemapAccesskeys.js', 'MediaWiki:WHAM/code.2.js', 'MediaWiki:NullEditButton/code.js', 'MediaWiki:View_Source/code.js', 'MediaWiki:AjaxBatchDelete.js', 'MediaWiki:LastEdited/code.js', 'MediaWiki:CustomizeAce.js', 'MediaWiki:ProtectionIcons.js', 'MediaWiki:ShowWROnToolbar.js', 'MediaWiki:InterwikisOnSpecialPages.js' ];		}

function concatPages { return getCodePages.join('|'); }

function getImportQuery { return { mode: 'articles', only: 'scripts', articles: concatPages };		}

function importCodes { const devLoad = 'https://dev.fandom.com/load.php'; const rlModules = [ 'mediawiki.Uri', 'ext.fandom.ContentReview.legacyLoaders.js' ];

mw.loader.using( rlModules, function {				const devUri = new mw.Uri( devLoad );

devUri.query = getImportQuery; mw.loader.load( devUri.toString ); } );		}

return importCodes; };

self.init = function { // WHAM window.WHAMDeleteReason = self.msg( 'summary-housekeeping', 'content' ); window.WHAMBlockReason = self.msg( 'summary-vandalism', 'content' );

// I don't like this thing – kill WikiActivity window.UCP = window.UCP || {}; window.UCP.WikiActivity = window.UCP.WikiActivity || {}; window.UCP.WikiActivity.loaded = true;

// Custom Ace editor window.aceCustomSettings = { theme: ( self.isDarkWiki				? 'dracula'				: 'dawn'			), wrap: true, showInvisibles: true };

// FastDelete buttons window.fdButtons = [ {				summary: self.msg( 'summary-housekeeping', 'content' ), label: 'HK' },			{				summary: self.msg( 'summary-spam', 'content' ), label: 'S'			}, {				summary: self.msg( 'summary-vandalism', 'content' ), label: 'V'			}, {				summary: self.msg( 'summary-tou', 'content' ), label: 'ToU' }		];

// DotSyntaxHighlighter var syntaxHighlighterSiteConfig = syntaxHighlighterSiteConfig || {}; syntaxHighlighterSiteConfig.timeout = 150;

// AjaxBatchDelete window.batchDeleteDelay = 125;

// LastEdited window.lastEdited = { avatar: false };

// RemapAccesskeys window.customKeyboardShortcuts = [ {				selector: '.content-size-toggle', accesskey: '1' },			{				selector: '.right-rail-toggle', accesskey: '2' },			{				selector: '.skin-theme-toggle-temporal', accesskey: '3', hook: 'dev.themeToggler.loaded' },			{				selector: '.toolbar a[data-name="wikifactory"]', accesskey: '4' }		];

// Run modules self.importDevCodes; self.snippets;

// Import SOAP goodies mw.loader.load( 'https://internal-soap.fandom.com/wiki/User:Rail/scripts.js?action=raw&ctype=text/javascript' ); };

self.init; } )( mediaWiki, this );