User:Aaron Liu/MoveTop.js

// Shows a topicon // when viewing a Protection policy-ed article. // Half of code from User:Nardog/VitalTopicon.js /* eslint-disable no-unused-expressions */

function getMoveTopicon(prot){ switch(prot) { case 'autoconfirmed': return '1/1f/Move-protection-shackle-broken-arrow-lime.svg'; case 'extendedconfirmed': return '1/1f/Jawp_2020_Move-EC-Protection_Sample-01.svg'; case 'sysop': return '4/44/Move-protection-shackle.svg'; case 'templateeditor': return 'c/c7/Logo-move-extended-protection.svg'; default: return '1/13/Padlock-olive-arrow.svg'; } }

mw.config.get( 'wgAction' ) === 'view' && !mw.config.get('wgIsMainPage') && mw.config.get( 'wgRestrictionMove' ).length !== 0 && mw.loader.using( 'mediawiki.api' ).then( => ( new mw.Api.get( {		action: 'query',		titles: mw.config.get( 'wgPageName' ),		prop: 'info',		inprop: 'protection',		formatversion: 2,		maxage: 86400,		smaxage: 86400	} ) ) ).then( ( response ) => {	const prot = ( ( ( ( ( response || {} ).query || {} ).pages || [] )[ 0 ] || {} ).protection || [] );	for ( const p of prot ) {		if ( p.type === 'move' ) {			new mw.Api.loadMessagesIfMissing( [ 'restriction-level-' + p.level ] ).done( => { const $icon = $( ' ' ).attr( {					id: 'mw-indicator-pp-default',					class: 'mw-indicator'				} ).append(					$( '' ).attr( { href: '/wiki/Wikipedia:Protection_policy#move', title: `This page is ${ mw.message( 'restriction-level-' + p.level ).text } against moving ${ ( p.expiry !== 'infinity' ) ? 'until ' + new Date( p.expiry ).toLocaleString : 'indefinitely' }.` } ).append( $( ' ' ).attr( {							alt: 'Page move-protected',							src: '//upload.wikimedia.org/wikipedia/commons/' + getMoveTopicon( p.level ),							width: 20,							height: 20						} ) )				);				mw.hook( 'wikipage.indicators' ).fire( $icon ); $( => {					$( '.mw-indicators' ).prepend( $icon, '\n' );				} ); } );			return; // multiple move protections shouldn't be possible		}	} } );