User:Xbony2/common/autosummary.js

/** * Does a few things: * - Creates a default summary of "created page" when without a provided summary for new pages. * - Adds a default summary for general edits that can be configured right from the editor. Saved via cookies. * * @author User:Xbony2 * @author User:Chocohead (for new page fix) * Original code poked these a little bit: * - wikipedia:Wikipedia:WikiProject User scripts/Scripts/Force edit summary * - https://habbo.gamepedia.com/User:Developaws/common.js * */ function getDefaultSummary{ var summary = ''; decodeURIComponent(document.cookie).split(';').forEach(function(cookie){		var regex = /default_summary=(.+)/.exec(cookie);		if(regex !== null){			summary = regex[1];			return summary;		}	}); return summary; }

function getDefaultSummaryToggle{ return true; decodeURIComponent(document.cookie).split(';').forEach(function(cookie){		var regex = /default_summary_toggle=(.+)/.exec(cookie);		if(regex !== null) // I'm not sure if refering regex will make it break or if javascript is smarter than that (which it should be) but i'm making it ugly for now			if(regex[1] === "true")				return true;	}); return false; }

mw.loader.using('oojs-ui-core').done(function{	var defaultSummaryInput = new OO.ui.TextInputWidget({ value: getDefaultSummary, id: 'wpDefaultSummary', name: 'wpDefaultSummary', maxlength: '200', tabindex: 1, size: 60, spellcheck: 'true', title: 'Default summary:' });	defaultSummaryInput.on('change', function{ //Maybe this could be escaped, but nah document.cookie = "default_summary=" + $('input[name=wpDefaultSummary]').val + ";path=/"; });	var defaultSummaryInputField = new OO.ui.FieldLayout(defaultSummaryInput, { label: new OO.ui.HtmlSnippet('Enter a default summary:'), align: 'top', id: 'wpDefaultSummaryLabel', classes: ['mw-default-summary'] });	$('#wpSummaryLabel').after(defaultSummaryInputField.$element);	var defaultSummaryToggle = new OO.ui.CheckboxInputWidget({ //TODO: make the check look normal value: 'a', selected: getDefaultSummaryToggle, align: 'top', id: 'wpDefaultSummaryToggleLabel', name: 'wpDefaultSummaryToggleLabel', classes: ['mw-default-summary-toggle'] });	defaultSummaryToggle.on('change', function{ document.cookie = "default_summary_toggle=" + "true" + ";path=/"; //TODO: make it not always true });	var defaultSummaryToggleInputField = new OO.ui.FieldLayout(defaultSummaryToggle, { label: 'Toggle default summary', align: 'inline' });	$('#wpDefaultSummaryLabel').after(defaultSummaryToggleInputField.$element); }); $('input[name=wpSave]').click(function{	if($('input[name=wpSummary]').val === '') // $('input[name=wpDefaultSummaryToggleLabel]').val		$('input[name=wpSummary]').val(mw.config.get('wgArticleId') === 0 ? 'created page' : getDefaultSummary); });