User:MrJaroslavik/global.js

mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:BrandonXLF/UpdateNotifications.js&action=raw&ctype=text/javascript');

mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Enterprisey/diff-permalink.js&action=raw&ctype=text/javascript');

mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Awesome Aasim/rollbacknoleave.js&action=raw&ctype=text/javascript');

mw.config.get('wgCanonicalSpecialPageName') === 'CentralAuth' && $(function sortCentralAuthByEditCount {	let th = document.querySelector('.mw-centralauth-wikislist th:nth-child(6)');	if (!th) return;	let sort = => {		if (!th.classList.contains('headerSort')) return;		for (let i = 0; i < 3; i++) {			if (th.classList.contains('headerSortDown')) return true;			th.click;		}	};	if (sort) return;	let observer = new MutationObserver( => { sort && observer.disconnect; });	observer.observe(th, { attributes: true });	let $table = $('.mw-centralauth-wikislist');	if ($table.hasClass('jquery-tablesorter')) return;	mw.loader.using('jquery.tablesorter', => { $table.tablesorter; }); });

mw.loader.using( 'mediawiki.user', function {	if ( mw.user.options.get( 'language' ) !== 'en' ) {		( new mw.Api ).postWithToken( 'csrf', { action: 'options', change: 'language=en' } ).then( function { mw.notify( 'Language has been changed to English. Please refresh the page.' ); } );	} else {		console.log( 'Language already set to English!' );	} } );

// DATABASENAME OF WIKI BEFORE USERNAME $('#pt-userpage').prepend('['+mw.config.get('wgDBname')+']  ');

// REDIRECT TO META IF ACCESS TO LOCAL CENTRALAUTH PAGE if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'CentralAuth' && mw.config.get('wgDBname') != 'metawiki' ){ location.href = '//meta.miraheze.org/wiki/Special:CentralAuth/' + mw.util.wikiUrlencode( mw.config.get( 'wgRelevantUserName' ) ); }

// SUBPAGES

$(function {	mw.util.addPortletLink( 'p-cactions', "//" + window.location.hostname + mw.config.get('wgArticlePath').replace('$1', "Special:PrefixIndex/" + encodeURIComponent(mw.config.get('wgPageName')) + "/"), 'Subpages', 'subpages', 'View subpages', 's'	); });

//SMART ROLLBACK by Hoo_Man mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hoo_man/smart_rollback.js&action=raw&ctype=text/javascript'); if(typeof(smartRollbackConfig) === 'undefined') smartRollbackConfig = {}; smartRollbackConfig.enableMarkbotedits = true;

// USER INFO if ( [ 2, 3 ].indexOf( mw.config.get( 'wgNamespaceNumber' ) ) !== -1 && ( !mw.config.get( 'wgArticleId' ) || mw.config.get( 'wgAction' ) === 'view' ) ) mw.loader.load( '//test.wikipedia.org/w/index.php?title=User:MrJaroslavik/test.js&action=raw&ctype=text/javascript' );

// TOGGLE SIDEBAR mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:BrandonXLF/ToggleSidebar.js&action=raw&ctype=text/javascript');

// SIDEBAR // LOCK THIS USER mw.loader.using(['mediawiki.util']).done(function{	var user = mw.config.get( 'wgRelevantUserName' );	if( user !== null && !mw.util.isIPAddress(user) ){		mw.util.addPortletLink( 'p-tb', 'https://meta.miraheze.org/w/index.php?title=Special:MultiLock&wpTarget=' + user, 'Lock', 't-lock', 'Lock this user' );	} });

// CENTRAL AUTH mw.loader.using(['mediawiki.util']).done(function{	var user = mw.config.get( 'wgRelevantUserName' );	if( user !== null && !mw.util.isIPAddress(user) ){		mw.util.addPortletLink( 'p-tb', 'https://meta.miraheze.org/w/index.php?title=Special:CentralAuth/' + user, 'CentralAuth', 't-centralauth', 'Go to CentralAuth page of this user' );	} });

// SIDEBAR LINKS $( function {	var separator = ' / ';	var metaFQDN = 'meta.miraheze.org';	$("#p-navigation").after( $(	' ',			{				'class': 'portal',				'role': 'navigation',				'id': 'p-listusers'			}		).append(			$(	' ', {					'lang': 'en', 'dir': 'ltr', 'id': 'p-privileged_users-label', 'text': 'ListUsers' }			),			$( ' ', { 'class': 'body' } ).append( $( '' ).append(					$( '', { 'id': 't-listusers' } ).append( $(	'',							{								'href': '/wiki/Special:ListUsers/sysop',								'title': 'List Admins',								'text': 'A'							}						), separator, $(	'',							{								'href': '/wiki/Special:ListUsers/bureaucrat',								'title': 'List Bureaucrats',								'text': 'B'							}						), separator, $(	'',							{								'href': '/wiki/Special:ListUsers/checkuser',								'title': 'List CheckUsers',								'text': 'CU'							}						), separator, $(	'',							{								'href': '/wiki/Special:ListUsers/oversight',								'title': 'List Oversighters',								'text': 'OS'							}						) )				)			)		 ), 		$(	' ',			{				'class': 'portal',				'role': 'navigation',				'id': 'p-importantpages'			}		).append(			$(	' ', {					'lang': 'en', 'dir': 'ltr', 'id': 'p-importantpages', 'text': 'Important Pages' }			),			$( ' ', { 'class': 'body' } ).append( $( '' ).append(					$( '', { 'id': 't-allpages' } ).append( $(	'',							{								'href': '/wiki/Special:PrefixIndex',								'title': 'AllPages',								'text': 'AllPages'							}						) ), $( '', { 'id': 't-meta-rc' } ).append( $(	'',							{								'href': 'https://meta.wikimedia.org/wiki/Special:RecentChanges',								'title': 'Meta-Wiki',								'text': 'WMF Meta'							}						) ),

$( '', { 'id': 't-meta-requestwikiqueuee' } ).append(						$(	'', {								'href': 'https://meta.miraheze.org/wiki/Special:RequestWikiQueue', 'title': 'RequestWikiQueue on Meta', 'text': 'RequestWikiQueue' }						)					), 										$( '', { 'id': 't-metamultilock' } ).append(						$(	'', {								'href': 'https://meta.miraheze.org/wiki/Special:MultiLock', 'title': 'MultiLock on Meta', 'text': 'MultiLock' }						)					), 										$( '', { 'id': 't-GlobalBlock' } ).append(						$(	'<a>', {								'href': 'https://meta.miraheze.org/wiki/Special:GlobalBlock?wpExpiry=6+months&wpReason=Web+host+or+proxy.+Contact+cvt[at]miraheze.org+if+affected.', 'title': 'GlobalBlock on Meta', 'text': 'GlobalBlock' }						)					), 					$( '<li>', { 'id': 't-loginwiki-rc' } ).append(						$(	'<a>', {								'href': 'https://login.miraheze.org/wiki/Special:RecentChanges', 'title': 'Login-Wiki RC', 'text': 'Login RC' }						)					), 					$( '<li>', { 'id': 't-metawiki-rc' } ).append(						$(	'<a>', {								'href': 'https://meta.miraheze.org/wiki/Special:RecentChanges', 'title': 'Meta RecentChanges', 'text': 'Meta RC' }						)					) 				) 			) 		), 		$(	' ',			{				'class': 'portal', 'role': 'navigation', 'id': 'p-logs' }		).append( $(	' ',				{					'lang': 'en',					'dir': 'ltr',					'id': 'p-logs-label',					'text': 'Logs'				}			), $( ' ', { 'class': 'body' } ).append(				$( '<ul>' ).append( $( '<li>', { 'id': 't-logs-links' } ).append(                                                $(	'<a>', {								'href': '/wiki/Special:AbuseLog', 'title': 'AbuseLog', 'text': 'A'							} ),						separator,						$(	'<a>', {								'href': '/wiki/Special:Logs/block', 'title': 'Blocks', 'text': 'B'							} ),						separator,						$(	'<a>', {								'href': '/wiki/Special:CheckUserLog', 'title': 'CheckUserLog', 'text': 'CU' }						),						separator,						$(	'<a>', {								'href': '/wiki/Special:Logs/delete', 'title': 'Deletions', 'text': 'D'							} ),						separator,						$(	'<a>', {								'href': 'https://meta.miraheze.org/wiki/Special:Log/globalauth', 'title': 'Global Locks', 'text': 'L'							} ),						separator,												$(	'<a>', {								'href': '/wiki/Special:Logs/managewiki', 'title': 'ManageWiki Log', 'text': 'MW' }						),						separator,						$(	'<a>', {								'href': '/wiki/Special:Logs/protect', 'title': 'Protections', 'text': 'P'							} ),						separator,						$(	'<a>', {								'href': '/wiki/Special:Logs/rights', 'title': 'Rights Log', 'text': 'R'							} ),

separator, $(	'<a>',							{								'href': '/wiki/Special:Logs/suppress',								'title': 'SuppressionLog',								'text': 'S'							}						),

) 				) 			) 		 )

); });

// BUTTONS // VERTICAL BAR mw.loader.using('user.options', function { if(mw.user.options.get('usebetatoolbar')) {    mw.loader.using('ext.wikiEditor', function { $(function {     	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { section: 'advanced', group: 'format', tools: { buttonId: { label: 'Vertical Bar', type: 'button', icon: 'https://upload.wikimedia.org/wikipedia/commons/3/32/Toolbaricon_vertical_bar.png', action: { type: 'encapsulate', options: { pre: '', peri: '|', post: '' }               }            }        }      	});      });    });  } });

// INTERLINK mw.loader.using('user.options', function { if(mw.user.options.get('usebetatoolbar')) {    mw.loader.using('ext.wikiEditor', function { $(function {     	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { section: 'advanced', group: 'format', tools: { buttonId: { label: 'InterLink', type: 'button', icon: 'https://upload.wikimedia.org/wikipedia/commons/9/97/Button_int_link.png', action: { type: 'encapsulate', options: { pre: ,                       peri: ,                        post: '' }               }            }        }      	});      });    });  } });

// TEMPLATE mw.loader.using('user.options', function { if(mw.user.options.get('usebetatoolbar')) {    mw.loader.using('ext.wikiEditor', function { $(function {     	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { section: 'advanced', group: 'format', tools: { buttonId: { label: 'Template', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/e/eb/Button_plantilla.png', action: { type: 'encapsulate', options: { pre: '' }               }            }        }      	});      });    });  } });

// QUOTES mw.loader.using('user.options', function { if(mw.user.options.get('usebetatoolbar')) {    mw.loader.using('ext.wikiEditor', function { $(function {     	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { section: 'advanced', group: 'format', tools: { buttonId: { label: 'Quotes', type: 'button', icon: 'https://upload.wikimedia.org/wikipedia/commons/6/65/Upper_apostrophe_toolbar_symbol.png', action: { type: 'encapsulate', options: { pre: '"',                       peri: '',                        post: '"' }               }            }        }      	});      });    });  } });

// COMMENT mw.loader.using('user.options', function { if(mw.user.options.get('usebetatoolbar')) {    mw.loader.using('ext.wikiEditor', function { $(function {     	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { section: 'advanced', group: 'format', tools: { buttonId: { label: 'Comment', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/f/f9/Toolbaricon_regular_S_stroke.png', action: { type: 'encapsulate', options: { pre: '' }               }            }        }      	});      });    });  } });

// SIGN mw.loader.using('user.options', function { if(mw.user.options.get('usebetatoolbar')) {    mw.loader.using('ext.wikiEditor', function { $(function {     	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { section: 'advanced', group: 'format', tools: { buttonId: { label: 'Sign', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/7/79/Insert-signature.png', action: { type: 'encapsulate', options: { pre: '', peri: '', post: '--\x7E\x7E\x7E\x7E' }               }            }        }      	});      });    });  } });

// PING mw.loader.using('user.options', function { if(mw.user.options.get('usebetatoolbar')) {    mw.loader.using('ext.wikiEditor', function { $(function {     	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { section: 'advanced', group: 'format', tools: { buttonId: { label: 'Ping', type: 'button', icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Arr.svg/18px-Arr.svg.png', action: { type: 'encapsulate', options: { pre: '\x7b\x7bping|', peri: '', post: '}}--\x7E\x7E\x7E\x7E' }               }            }        }      	});      });    });  } });

// mark as patrolled globally /** * Adds a [mark as patrolled] link to change list items, which have the red exclamation mark. */ /*global mw, $ */ /*jslint vars: true, unparam: true, white: true */ ( function {	'use strict';

if (		mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Watchlist' &&		mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Recentchanges' &&		mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Recentchangeslinked'	) { return; }

var messages = 'markaspatrolleddiff';

function markPatrolled( event ) { new mw.Api .postWithToken( 'patrol', { formatversion: 2, action: 'patrol', revid: event.data.revid } ) .then( function {			$( event.target ).closest( '.patrollink' ).remove;		} ); event.preventDefault; }

function main( element ) { $( element ).find( 'abbr.unpatrolled' ).closest( 'li, tr' ).each( function {			var href = $( this ).find( 'a[href*="&diff="]' ).attr( 'href' );			if ( href === undefined ) {				return;			}

var revid = href.match( /&diff=(\d*)/ )[ 1 ]; if ( revid === '0' ) { revid = href.match( /&oldid=(\d*)/ )[ 1 ]; }

var $target = this.nodeName === 'TR' ? $( this ).children( 'td:last' ) : $( this );

$target .append( ' ',				$( ' ' ).addClass( 'patrollink' )				.append( '[', $( '<a>' ).attr( 'href', '#' ) .text( mw.msg( 'markaspatrolleddiff' ) ) .click( { revid: revid }, markPatrolled ), ']' )			);		} );	}

new mw.Api.loadMessages( messages ) .then( function {		mw.hook( 'wikipage.content' ).add( main );	} );

} );

// CUSTOM SIDEBAR $( function {	var separator = ' / ';	var metaFQDN = 'meta.miraheze.org';	$("#p-navigation").after( $(	' ',			{				'class': 'portal',				'role': 'navigation',				'id': 'p-managewiki'			}		).append(			$(	' ', {					'lang': 'en', 'dir': 'ltr', 'id': 'p-managewiki-label', 'text': 'ManageWiki' }			),			$( ' ', { 'class': 'body' } ).append( $( '<ul>' ).append(					$( '<li>', { 'id': 't-managewiki-links' } ).append( $(	'<a>',							{								'href': '/wiki/Special:ManageWiki/core',								'title': 'Core',								'text': 'C'							}						), separator, $(	'<a>',							{								'href': '/wiki/Special:ManageWiki/extensions',								'title': 'Extensions',								'text': 'E'							}						), separator, $(	'<a>',							{								'href': '/wiki/Special:ManageWiki/namespaces',								'title': 'Namespaces',								'text': 'N'							}						), separator, $(	'<a>',							{								'href': '/wiki/Special:ManageWiki/permissions',								'title': 'Permissions',								'text': 'P'							}						), separator, $(	'<a>',							{								'href': '/wiki/Special:ManageWiki/settings',								'title': 'Additional',								'text': 'A'							}						) ) 				) 			) 		 )

); });

// // @ts-check // Companion to markblocked - asynchronously marks locked users // Chunks borrowed from User:Krinkle/Scripts/CVNSimpleOverlay_wiki.js, // User:GeneralNotability/ip-ext-info.js, and MediaWiki:Gadget-markblocked.js

/** * Get all userlinks on the page * * @param {JQuery} $content page contents * @return {Map} list of unique users on the page and their corresponding links */ function lockedUsers_getUsers($content) { const userLinks = new Map;

// Get all aliases for user: & user_talk: (taken from markblocked) const userNS = []; for ( const ns in mw.config.get( 'wgNamespaceIds' ) ) { if ( mw.config.get( 'wgNamespaceIds' )[ns] === 2 || mw.config.get( 'wgNamespaceIds' )[ns] === 3 ) { userNS.push( mw.util.escapeRegExp(ns.replace( /_/g, ' ' )) + ':' ); }	}

// RegExp for all titles that are User:| User_talk: | Special:Contributions/ (for userscripts) const userTitleRX = new RegExp( '^(' + userNS.join( '|' ) + '|' + 'Special:Contributions' + '\\/)+([^\\/#]+)$', 'i' ); const articleRX = new RegExp( mw.config.get( 'wgArticlePath' ).replace('$1', '') + '([^#]+)' ); $('a', $content).each(function {		if (!$(this).attr('href')) {			// Ignore if the <a> doesn't have a href			return;		}		const articleTitleReMatch = articleRX.exec($(this).attr('href').toString);		if (!articleTitleReMatch) {			return;		}		const pgTitle = decodeURIComponent( articleTitleReMatch[1] ).replace( /_/g, ' ' );		const userTitleReMatch = userTitleRX.exec(pgTitle);		if (!userTitleReMatch) {			return;		}		const username = userTitleReMatch[2];		if (!mw.util.isIPAddress(username, true)) {			if (!userLinks.get(username)) {				userLinks.set(username, []);			}			userLinks.get(username).push($(this));		}	}); return userLinks; }

/** * Check whether a user is locked * * @param {string} user Username to check * * @return {Promise } Whether the user in question is locked */ async function lockedUsers_isLocked(user) { const api = new mw.Api; try { const response = await api.get({			action: 'query',			list: 'globalallusers',			agulimit: '1',			agufrom: user,			aguto: user,			aguprop: 'lockinfo'		}); if (response.query.globalallusers.length === 0) { // If the length is 0, then we couldn't find the global user return false; }		// If the 'locked' field is present, then the user is locked return 'locked' in response.query.globalallusers[0]; } catch (error) { return false; } }

// On window load, get all the users on the page and check if they're blocked $.when( $.ready, mw.loader.using( 'mediawiki.util' ) ).then( function {	mw.hook('wikipage.content').add(function ($content) { const usersOnPage = lockedUsers_getUsers($content); usersOnPage.forEach(async (val, key, _) => {			const userLocked = await lockedUsers_isLocked(key);			if (userLocked) {				val.forEach(($link) => { $link.css({ opacity: 0.4, 'border-bottom-size': 'thick', 'border-bottom-style': 'dashed', 'border-bottom-color': 'red' }); });			}		});	}); });