User:Writ Keeper/Scripts/blockDefaults.js

importScript("Special:MyPage/defaultBlockSettings.js");

$(document).ready(function {	mw.loader.using( ['mediawiki.util', 'mediawiki.user'], function { if(mw.config.get("wgCanonicalSpecialPageName") === "Block") {			if(typeof wkDefaultBlockSettings === "undefined") {				wkDefaultBlockSettings = {"Revoking talk page access: inappropriate use of user talk page while blocked":{"mw-input-wpDisableUTEdit":"checked"},"":{"mw-input-wpCreateAccount":"unchecked","mw-input-wpDisableEmail":"unchecked","mw-input-wpDisableUTEdit":"unchecked","mw-input-wpAutoBlock":"unchecked"}}; }			$("#mw-input-wpReason").change(function			{				if(wkDefaultBlockSettings != null)				{					var defaults = wkDefaultBlockSettings[$("#mw-input-wpReason").val];					if(typeof defaults !== "undefined")					{						var defaultKeys = Object.keys(defaults);						for(var i = 0; i < defaultKeys.length; i++)						{							if(defaults[defaultKeys[i]] === "checked")							{								$("#"+defaultKeys[i]).prop('checked', true);							}							else if(defaults[defaultKeys[i]] === "unchecked")							{								$("#"+defaultKeys[i]).prop('checked', false);							}						}					}				}			}); $("#mw-input-wpReason").after(" To adjust the default settings for the different block types, please go to this page. "); }		else if(mw.config.get("wgPageName") === "User:" + mw.config.get("wgUserName").replace(" ", "_") + "/defaultBlockSettings") {			if(typeof wkDefaultBlockSettings === "undefined") {				wkDefaultBlockSettings = {"Revoking talk page access: inappropriate use of user talk page while blocked":{"mw-input-wpDisableUTEdit":"checked"},"":{"mw-input-wpCreateAccount":"unchecked","mw-input-wpDisableEmail":"unchecked","mw-input-wpDisableUTEdit":"unchecked","mw-input-wpAutoBlock":"unchecked"}}; }			var reasonList = 'Vandalism Vandalism-only account Violations of the Biographies of living persons policy Using Wikipedia for spam or advertising purposes Spam / advertising-only account Creating attack, nonsense or other inappropriate pages Copyright violations Abusing multiple accounts Block evasion Personal attacks or harassment Edit warring Violation of the three-revert rule <option value="Disruptive editing">Disruptive editing <option value="Making legal threats">Making legal threats <option value="Arbitration enforcement">Arbitration enforcement <option value="Deliberately triggering the Edit filter">Deliberately triggering the Edit filter <option value="Long term abuse">Long term abuse <option value="Revoking talk page access: inappropriate use of user talk page while blocked">Revoking talk page access: inappropriate use of user talk page while blocked <optgroup label="Templated reasons"><option value=""> <option value=""> <option value=""> <option value=""> <option value=""> <option value=""> <option value=""> <option value=""> <option value=""> <option value=""> <option value=""> <option value=""> <option value=""> <option value="">   '; $("#mw-content-text").html(' Welcome to the default block setup screen! To use this screen, simply select one of the preloaded block reasons from the menu below, select the options you wish to make the default for that block reason, and hit the "Save as default" button. When you\'re done with all of them, hit the "Finished" button, and your preferences will be saved in an automated edit to your common.js page. TAKE NOTE: your changes are not truly permanent until you\'ve hit the "Finished" button; if you leave the page before doing so, your changes will be lost. Also, after hitting "Finished" and seeing the confirmation box pop up, you may need to <a href="'+ mw.util.getUrl("WP:BYPASS") +'" target="_blank">bypass your cache</a> to see the changes.If you\'ve never done this before, there are a few settings that come with; if you have, then you\'ll be able to see your currently-set preferences as well.'); $("#mw-content-text").append(" Settings " + reasonList + " <input type='button' id='saveItemPrefs' value='Save as default'><input type='button' id='finalizePrefs' value='Finished'>"); $("#mw-input-wpReason").change(function			{				var settings;				if(typeof wkDefaultBlockSettings === "undefined" || wkDefaultBlockSettings === null || typeof wkDefaultBlockSettings[$("#mw-input-wpReason").val] === "undefined")				{					settings = null;				}				else				{					settings = wkDefaultBlockSettings[$("#mw-input-wpReason").val];				}				$("#blockOptionsTable .currentSetting").each(function(ind, el) {					if(settings != null && typeof settings[$(el).attr("name")] !== "undefined") {						$(el).html(settings[$(el).attr("name")]); }					else {						$(el).html("don't change"); }				});			});			$("#saveItemPrefs").click(function			{				var checkedItems = $("input:checked");				var outputArray = {};				checkedItems.each(function(ind, el) {					if($(el).attr("value") !== "nochange") {						outputArray[$(el).attr("name")] = $(el).attr("value"); }				});				wkDefaultBlockSettings[$("#mw-input-wpReason").val] = outputArray;				$("#mw-input-wpReason").change;			}); $("#finalizePrefs").click(function			{				var contentString = "wkDefaultBlockSettings = " + JSON.stringify(wkDefaultBlockSettings)+";";				contentString = contentString.replace(/\\"/g, '"').replace(/= \"{/, '= {').replace(/}";/, '};');				var requestData = {action: "edit", title: "User:" + mw.config.get("wgUserName") + "/defaultBlockSettings.js", text: contentString, summary:"Updating default block setting preferences.", minor:"true", token: mw.user.tokens.get( 'csrfToken' )};				$("#finalizePrefs").val("Saving...");				$.post(mw.config.get("wgScriptPath") + "/api.php", requestData, function {					$("#finalizePrefs").val("Finished"); alert("Save complete!"); });			});		}	}); });