User:ToxiBoi/SummaryBrute.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var path = document.location.href;
var regex = /(wiki|w)\/(index\.php\?title=|)Draft:.*(\?|&)action=(edit.*&preload=Template:AFC_submission\/Subst.*|submit)/gi;
var override = /&toxiran=1/;
var version = "v1.6.1";

var ad = " (using [[User:ToxiBoi/SummaryBrute|SB "+version+"]])";

function AskForConfirmation() {
	if (window.ToxiSummaryBrute.BypassDialog === true) {
		return true;
	} else {
		return confirm('It looks like you are trying to submit a draft. Would you like to activate SummaryBrute?');
	}
}

var IfSubmit = regex.test(path);
console.log("SummaryBrute Results (Submission): "+IfSubmit);
var IfOverride = override.test(path);
console.log("SummaryBrute Results (Override): "+IfOverride);

if (IfOverride) {
	mw.notify("SummaryBrute has finished. You should now be able to submit without any problems.");
}

if (IfSubmit === true && IfOverride === false && AskForConfirmation()) {
	mw.notify("Running SummaryBrute...");
	document.location.href = path+"&toxiran=1&summary=Submitting draft"+ad;
}