User:Voice of Clam/common.js

window.HotCatAutoRemoveCheckCat = true; window.hotcat_dont_add_to_watchlist = true;

var wma_settings = {enabled:false}

function classicLogoutConfirmInit {	var classic_logout_confirm_href; var classic_logout_confirm_element; var classic_logout_confirm_count=-1; var classic_logout_confirm_aze=document.getElementsByTagName("a"); while(classic_logout_confirm_element=classic_logout_confirm_aze[(++classic_logout_confirm_count)]) {		classic_logout_confirm_href=classic_logout_confirm_element.getAttribute("href"); if(classic_logout_confirm_href) {			if(classic_logout_confirm_href.indexOf("title=Special:UserLogout")!=-1) {				classic_logout_confirm_element.setAttribute("onclick","return confirm('Are you sure you want to log out?')"); return; }		}	} }

jQuery(document).ready(classicLogoutConfirmInit);

// Code by User:Jarry1250 to stop the "return" key taking effect in the "edit summary" box $(".mw-summary").keypress(function(e){ if (e.which == 13) { return false; } } );

/* Add a "Safe mode" sidebar link to reload the current page with safemode=1 added. Copied from User:PrimeHunter/Safe mode.js

$( document ).ready( function { mw.util.addPortletLink( 'p-tb', location.href.replace( location.hash, '' ) + ( location.search ? '&' : '?' ) + 'safemode=1', 'Safe mode', 't-safemode', 'Reload page without user js, css and gadgets (discards anything you have entered)' ); });

/* Alternative main page */

if ( mw.config.get( "wgPageName" ) == "Main_Page" ) { location.href = mw.util.getUrl( "User:Voice of Clam/MPA" ); }

/** * Auto-number headings * * @source https://www.mediawiki.org/wiki/Snippets/Auto-number_headings * @author Krinkle * @version 2021-10-03 */ var toc = document.querySelector('#toc'); if (toc) { document.querySelectorAll('.mw-parser-output :is(h1,h2,h3,h4,h5,h6) .mw-headline').forEach(function (headline) {   var num = toc.querySelector('a[href="#' + CSS.escape(headline.id) + '"] .tocnumber');    if (num) headline.prepend(num.textContent + ' ');  }); } else { document.body.classList.add('tpl-autonum'); }

/* Automate purge confirmation dialog */ if (mw.config.get('wgAction') === 'purge') { $('form[action*="action=purge"]').submit; }

//Mass rollback function //Written by John254 and modified/rewritten by Writ Keeper with modifications by TheDJ; original is at https://en.wikipedia.org/wiki/User:John254/mass_rollback.js //Adapted from User:Mr.Z-man/rollbackSummary.js //Instructions: Selecting the "rollback all" tab when viewing a user's contributions history //will open all rollback links displayed there. (Use with caution) if(typeof wkContribsCheckboxInit === "undefined") {	wkContribsCheckboxInit = false; }

function rollbackEverythingWKMR(editSummary) {	if(editSummary === null) {		return false; }	mw.loader.using( 'mediawiki.api' ).done( function	{		var rbMetadata = {};		rbMetadata.api = new mw.Api;		rbMetadata.userName = mw.config.get("wgRelevantUserName");		rbMetadata.ipRange = (rbMetadata.userName === null);		rbMetadata.titleRegex = /title=([^&]+)/;		rbMetadata.editSummary = editSummary;		$("a[href*='action=rollback']").each(function(ind, el) {			rollbackOneThingWKMR(el, rbMetadata); } );	} );	return false; } function rollbackSomeThingsWKMR(editSummary) {	if(editSummary === null) {		return false; }	mw.loader.using( 'mediawiki.api' ).done( function	{		var rbMetadata = {};		rbMetadata.api = new mw.Api;		rbMetadata.userName = mw.config.get("wgRelevantUserName");		rbMetadata.titleRegex = /title=([^&]+)/;		rbMetadata.editSummary = editSummary;		var rollbackList = $("input.revdelIds:checked").parents("li.mw-contributions-current").find("a[href*='action=rollback']");		if(rollbackList.length <= 0)		{			mw.notify("You didn't select any edits that could be rolled back!");			return;		}		$("input.revdelIds:checked").parents("li.mw-contributions-current").find("a[href*='action=rollback']").each(function(ind, el) {			rollbackOneThingWKMR(el, rbMetadata); } );	} ); } function rollbackOneThingWKMR(edit, rbMetadata) {	var userName; //if we're in an anonymous IP range, we have to figure out each username on its own, since they might be different for each edit. if(rbMetadata.userName === null) {		//the not clause is probably not necessary, but I'm including it just to be sure. userName = $(edit).parents("li:first").children("a.mw-anonuserlink").not(".mw-contributions-title").text; }	else {		userName = rbMetadata.userName; }	var params = {}; if( rbMetadata.editSummary != '' ) {		params.summary = rbMetadata.editSummary; }	rbMetadata.api.rollback( decodeURIComponent(rbMetadata.titleRegex.exec(edit.href)[1]), userName, params).done( function	{		$(edit).after("reverted");		$(edit).remove;	} ); } $(document).ready(function {	if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions" && $("span.mw-rollback-link").length > 0)	{		mw.loader.using("mediawiki.util").done( function {			mw.util.addPortletLink('p-cactions', '#', "rollback all", "ca-rollbackeverything", "rollback all edits displayed here"); if(!wkContribsCheckboxInit) {				if($("ul.mw-contributions-list .mw-revdelundel-link").length > 0) {					$("ul.mw-contributions-list .mw-revdelundel-link").each(function(ind,el){						if($(this).children("a").length > 0)						{							var revId = /ids=(\d+)/.exec($(this).children("a").attr("href"))[1];							var pageTitle = /target=([^&]+)/.exec($(this).children("a").attr("href"))[1];							$(el).prepend(" ");							$(el).children(".revdelIds").data("index", ind);						}					}); }				else {					$("ul.mw-contributions-list a.mw-changeslist-date").each(function(ind,el){						$(el).before(" ");					}); }				wkContribsCheckboxInit = true; }			mw.util.addPortletLink('p-cactions', '#', "rollback selected", "ca-rollbacksome", "rollback selected edits"); $("#ca-rollbackeverything").click( function(event)			{				event.preventDefault;				mw.loader.load( 'mediawiki.api' ); //start loading, while the user is in the prompt					return rollbackEverythingWKMR(prompt("Rollback all edits: Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the rollback entirely)"));			}); $("#ca-rollbacksome").click( function(event)			{				event.preventDefault;				mw.loader.load( 'mediawiki.api' ); //start loading, while the user is in the prompt					return rollbackSomeThingsWKMR(prompt("Rollback selected edits: Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the rollback entirely)"));			}); $("#ca-rollbacksome").data("lastSelectedIndex", -1);

$("input.revdelIds").off("click").click(				function(ev)				{					var lastSelectedRevdel = $("#ca-rollbacksome").data("lastSelectedIndex");					var newIndex = $(this).data("index")					if(ev.shiftKey && lastSelectedRevdel >= 0)					{						var checkboxArray = $("input.revdelIds");						var start = lastSelectedRevdel;						var stop = newIndex;						if(start < stop)						{							for(var i = start; i < stop; i++)							{								$(checkboxArray[i]).prop("checked", true);							}						}						else						{							for(var i = start; i > stop; i--)							{								$(checkboxArray[i]).prop("checked", true);							}						}					}					 $("#ca-rollbacksome").data("lastSelectedIndex", newIndex);				});

});	} });