User:Garzfoth/Scripts/SafetyEdit.js

// Migrated from https://en.wikipedia.org/wiki/User:Garzfoth/common.js on 2021-05-05

// Notes: // • For changelogs prior to migration, see https://en.wikipedia.org/w/index.php?title=User:Garzfoth/common.js&action=history // • TODO: Give this further attention.

// Originally from: User:Equazcion/SafetyEdit

if ((mw.config.get('wgAction') === "edit") || (mw.config.get('wgAction') === "submit")) { // Insert the checkbox mw.loader.using( [ 'oojs-ui-core' ] ).done(function {		/*var a = new OO.ui.CheckboxInputWidget({ selected: false });		var b = new OO.ui.ButtonWidget({ label: 'Ajax Preview', });*/		var c = new OO.ui.FieldLayout( new OO.ui.CheckboxInputWidget({				inputId: 'ruSure'				//data: ''				//id: 'ruSure',				//class: 'ruSure',				//selected: false			}), {				label: 'Enable save', align: 'inline' }		);		//c.on('change', onChange);		//b.on('click', AJAXPreview.doPreview);		//$( p ).before( b.$element, ' ' );		$('#mw-editpage-watch').after(c.$element);		var submitbtn = OO.ui.Element.static.unsafeInfuse('#wpSaveWidget', false);		// submitbtn.disabled => true/false		// submitbtn.setDisabled(true/false)		submitbtn.setDisabled(true);		$('#wpSave').css('pointer-events', 'none');		var locked = true;		// https://api.jquery.com/unbind/ -- this is likely why char counter is mostly broken. not sure what the best option is yet. jQuery 3 will depreciate .unbind btw.		// hmm, so unbind is used here differently than later on... maybe check if the change event is somehow firing?		$('#wpSummary').focus(function { //$(this).unbind; $(this).off("submit"); });		$('#ruSure').change(function { if ($(this).prop("checked")) { // We use the name attribute so all potential save buttons (produced by other scripts etc) are affected submitbtn.setDisabled(false); $('#wpSave').css('pointer-events', 'auto'); locked = false; // If checked, undo our summary line focus event from above //$('#wpSummary').unbind('focus'); $('#wpSummary').off('focus'); // Make enter key on summary line save again $('#wpSummary').keydown(function (event) {					if (event.keyCode == 13) {						$('form#editform').submit;						return false;					}				}); } else { submitbtn.setDisabled(true); $('#wpSave').css('pointer-events', 'none'); locked = true; // Here we can just unbind without a focus event, because MediaWiki JS won't supercede us again //$('#wpSummary').unbind; // Apparently that's incorrect... $('#wpSummary').focus(function {					//$(this).unbind;					$(this).off("submit");				}); // Or maybe this is the problem: $('#wpSummary').off("keydown"); }		});		var hoverTimeout;

$('#wpSaveWidget').mouseenter(function {			//console.log("mouseenter");			//$(this).delay(750).fadeTo("slow", 0.25); // also hits children, so its a problem			hoverTimeout = setTimeout(function  { if ($('#wpSaveWidget').is(':hover') && locked) { //console.log("hovertimeout has succeeded!"); $('#ruSure').click; }				//console.log("hovertimeout has triggered"); //$(this).delay(0).fadeTo("fast", 0); //$(this).stop.css('opacity', '0.25'); clearTimeout(hoverTimeout); }, 500);		}).mouseout(function {			//console.log("mouseout");			//$(this).stop.css('opacity', '0.25');			clearTimeout(hoverTimeout);		}); });	//	// extensive commented out code removed from here, see archives if it's needed down the line	// }