User:BryghtShadow/global.js

// window.EditConflictAlertInit = true; importArticles( {	type: 'script',	articles: [		// Regular scripts.		'u:dev:MediaWiki:HideEmptyTrackingCategories.js',		'u:dev:MediaWiki:ImportJSPage/code.js',		'u:dev:MediaWiki:MassCategorization/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 */ $(function {	if ($('.page.has-right-rail').length) return;

// @TODO: Add a configurable way to re-disable rail on certain pages, such as the main page?

var PreferencesHelper, tooltips, ofType, mustache, vignette, sponsoredContent; var isAnon = mw.user.isAnon;

// First ensure the aside element exists. function init { var visible = mw.user.options.get('rightrailvisible') === 'visible';

$('main.page__main').after(			$(' ', { 'class': 'page__right-rail' }).toggleClass('is-rail-hidden', !visible).append([ $(' ', {					'class': 'right-rail-toggle',					'data-wds-tooltip': mw.msg(visible ? 'hide' : 'show'),					'data-wds-tooltip-position': 'bottom'				}).append(					$(' ')				), $(' ', {					'class': 'right-rail-wrapper WikiaRail'				}).append([					$(' ', { id: 'rail-boxad-wrapper' }),					$(' ', { id: 'WikiaRail' })				]) ])		).parent.addClass('has-right-rail'); }

// Re-implemented for the following reasons: // 1. mw.config.get('wgRailModuleList') is null on pages without a rail. // 2. Originally has tracking, but doesn't feel right to track custom rail. // @See https://community.fandom.com/load.php?debug=false&lang=en&modules=skin.fandomdesktop.rail.lazyRail.js&skin=fandomdesktop function lazyRail { if ($('#p-tb').length) return; var sponsoredItemTemplate = '\n\t\n\t\n\t\t \n\t\t\n\t\t\t \n\t\t\n\t \n\n'; var RIGHT_RAIL_SELECTOR = '.right-rail-wrapper', SPONSORED_ITEM_THUMBNAIL_SIZE = 53;

function loadRail { var def = $.Deferred, searchParams = new URLSearchParams(window.location.search); $.get(mw.util.wikiScript('wikia'), {				'controller': 'Fandom\\FandomDesktop\\Rail\\RailController',				'method': mw.user.isAnon ? 'renderLazyContentsAnon' : 'renderLazyContents',				'modules': mw.config.get('wgRailModuleList') || (mw.user.isAnon ? [					'Fandom\\FandomDesktop\\Rail\\PopularPagesModuleService', ] : [					'Fandom\\FandomDesktop\\Rail\\PageToolsModuleService', 'Fandom\\FandomDesktop\\Rail\\RecentActivityModuleService' ]),				'params': mw.config.get('wgRailModuleParams'),				'fdRightRail': searchParams.get('fdRightRail'),				'uselang': searchParams.get('uselang'),				'useskin': 'fandomdesktop'			}).done(function (rail) {				rail = $(rail);				// Populate rail page tools with hidden page tools.				var hiddenPageTools = $('ul.page__hidden-page-tools');				var railPageTools = $('#p-tb > ul', rail);				railPageTools.append(hiddenPageTools.children);				def.resolve(rail);			}); return def.promise; }

// Sponsored Content ("Popular Pages") only applies to anons. // Fandom doesn't have this simple check. // Instead, "renderSponsoredContent" determines whether it's displayed. // So a network request is always sent...... function loadSponsored { return isAnon ? sponsoredContent.fetch : Promise.resolve(false); }

function renderSponsoredContent(e) { var t = $('.popular-pages__item', RIGHT_RAIL_SELECTOR); if (t.length) { if (e.thumbnailUrl && vignette.Vignette) { e.thumbnailUrl = vignette.Vignette.getThumbURL(e.thumbnailUrl, {						mode: vignette.Vignette.mode.smart,						height: SPONSORED_ITEM_THUMBNAIL_SIZE,						width: SPONSORED_ITEM_THUMBNAIL_SIZE					}); }				t.innerHTML = mustache.mustache.render(sponsoredItemTemplate, e); // if (e.pixelContent) { // 	sponsoredContent.insertTrackingPixel(e.pixelContent, e.pixelType); // }				// trackSponsoredContent(e.url); }		}

$(function {			$.when( loadRail, loadSponsored ).done(function (rail, sponsored) { $(RIGHT_RAIL_SELECTOR).append(rail); // ...What is this dispatch actually for? ofType.communicationService.dispatch({					type: '[Rail] Ready'				}); if (sponsored) { renderSponsoredContent(sponsored); }				// trackLazyRail; $('#WikiaRail').addClass('is-ready').trigger('afterLoad.rail'); });		});	}

// Re-implemented for the following reasons: // 1. Originally has tracking, but doesn't feel right to track custom rail. // @See https://community.fandom.com/load.php?debug=false&lang=en&modules=skin.fandomdesktop.rail.toggle.js&skin=fandomdesktop function railToggle { var HIDDEN_CLASS = 'is-rail-hidden', RAIL_OPTION_NAME = 'rightrailvisible', RAIL_VISIBLE = 'visible', RAIL_HIDDEN = 'hidden';

function setRightRailPreference(isVisible) { PreferencesHelper.setPreference(RAIL_OPTION_NAME, isVisible ? RAIL_HIDDEN : RAIL_VISIBLE); }

var rightRailToggle = $('.right-rail-toggle'), pageRightRail = $('.page__right-rail'); rightRailToggle.on('click', function {			var isVisible = pageRightRail.toggleClass(HIDDEN_CLASS).hasClass(HIDDEN_CLASS);			pageRightRail.attr('data-wds-tooltip', mw.msg(isVisible ? 'show' : 'hide'));			setRightRailPreference(isVisible);			// trackClick(isVisible);			setTimeout(function  { var ev = new Event('FandomDesktopContentSize'); window.dispatchEvent(ev); }, 300);		});	}

// Helper function function loadModules(names) { names = names.filter(Boolean); var moduleNames = mw.loader.getModuleNames; var fullNames = names.map(function (name) {			return moduleNames.find(function (mod) { return mod === name || mod.startsWith(name + '-'); });		});		return mw.loader.using(fullNames).then(function (require) {			var modules = {};			for (var i in names) {				modules[names[i]] = require(fullNames[i]);			}			return modules;		}); }

loadModules([		'skin.fandomdesktop.rail.css',		!isAnon && 'skin.fandomdesktop.rail.recentActivity.css',		isAnon && 'skin.fandomdesktop.rail.popularPages.css',		'PreferencesHelper',		'tooltips',		'ofType',		isAnon && 'mustache',		isAnon && 'vignette',		isAnon && 'sponsoredContent',		// 'skin.fandomdesktop.rail.toggle.js',		// 'skin.fandomdesktop.rail.lazyRail.js',	]).then(function (modules) {		PreferencesHelper = modules.PreferencesHelper;		tooltips = modules.tooltips;		ofType = modules.ofType;		mustache = modules.mustache;		vignette = modules.vignette;		sponsoredContent = modules.sponsoredContent;		init;		lazyRail;		railToggle;		tooltips.handleAllElementsWithTooltip;	}); });

/** Add cargo link */ $(function {	/** Restore link to Cargo's pagevalues **/	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] )		})	}	console.log('p-tb', document.getElementById('p-tb')); if (document.getElementById('p-tb')) { addLink; } else { $("#WikiaRail").on('afterLoad.rail', function {			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 ); } );	} ); } ); //