User:Garzfoth/Scripts/CustomEditSummaryPresets.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: Clean this up (variable names, formatting, syntax, etc), and figure out if I can safely inline the var declaration (it seems somewhat inefficient – if I could at least put it inside the if statement, that'd be a bit better).
// Custom edit summary presets
// Originally from: User:Equazcion/CustomSummaryPresets.js
// Original comments from source:
/**
* This is a modified version of User:ErrantX/defaultsummaries.js and User:MC10/defaultsummaries.js.
* This version displays a single menu of custom edit summaries across all namespaces.
* See User:Equazcion/CustomSummaryPresets for full instructions.
- /
//
// Legacy commented code removed, see archives if you need it for whatever reason
//
var customEditSummaryPresets = [
"assessment update (for WikiProject Pharmacology)",
"Copyedit",
"Fixing spelling/grammar issues",
"Fixing style/layout issues",
"Cleanup",
"Adding \"citation needed\" tag(s)",
"Adding/improving references",
"Adding/removing category/ies",
"Adding/removing external link(s)",
"Adding/removing wikilink(s)",
"Expanding article",
"Removing unsourced content",
"remove unsourced claim",
"remove unsourced information",
"remove irrelevant information",
"remove inaccurate information",
"expand ref",
"fix ref",
"Reply",
"Comment",
"Copyedit (major)",
"infobox additions",
"infobox fixes",
"rem unjustified claim(s)",
"adding/fixing wikilink(s)",
"Suggestion"
];
// Suggested:
// Removing wp:spam|linkspam per wp:el//
// cleanup
// (help:reverting) (vandalism) or test edit
// (help:reverting) unexplained content removal
// Common-general:
// Expanding article
// Adding/removing category/ies
// Adding/removing external link(s)
// Adding/removing wikilink(s)
// Removing unsourced content
// Removing wp:spam|linkspam per wp:el
// Clean up
// Copyedit (major)
// Common-talk:
// Reply
// Comment
// Suggestion
// (wikiproject link) tagging
// (wikiproject link) assessment
//Common-minor
// spelling/grammar correction
// fixing style/layout errors
// (help:reverting) (vandalism) or test edit
// (help:reverting) unexplained content removal
// copyedit (minor)
function editsummAddOptionToDropdown(dropdown, optionText) {
var option = document.createElement("option");
var optionTextNode = document.createTextNode(optionText);
option.appendChild(optionTextNode);
dropdown.appendChild(option);
}
function editsummAddCatToDropdown(dropdown, catText) {
var option = document.createElement("option");
option.disabled = true;
option.selected = true;
var optionTextNode = document.createTextNode(catText);
option.appendChild(optionTextNode);
dropdown.appendChild(option);
}
function editsummOnCannedSummarySelected() {
// Save the original value of the edit summary field
editsummOriginalSummary = document.getElementById("wpSummary");
if (editsummOriginalSummary) {
editsummOriginalSummary = editsummOriginalSummary.value;
} else {
editsummOriginalSummary = "";
}
var idx = this.selectedIndex;
var canned = this.options[idx].text;
var newSummary = editsummOriginalSummary;
// Append old edit summary with space, if exists,
// and last character != space
if (newSummary.length !== 0 && newSummary.charAt(newSummary.length - 1) !== " ") {
newSummary += " ";
}
newSummary += canned;
document.getElementById("wpSummary").value = newSummary;
}
if (mw.config.get('wgAction') === "edit" || mw.config.get('wgAction') === "submit") {
var editsummOriginalSummary = "";
var insertBeforeThis = document.getElementById("wpSummaryLabel");
// Loop through siblings, looking for editCheckboxes class
while (insertBeforeThis) {
if (insertBeforeThis.className === "editCheckboxes") {
break;
}
insertBeforeThis = insertBeforeThis.nextSibling;
}
// If we failed to find the editCheckboxes class, or insertBeforeThis is null
if (!insertBeforeThis || insertBeforeThis.className !== "editCheckboxes") {
//return;
// NOTE: For some idiotic reason alert() works great, but none of the other things I've tried do.
// So, this really needs a fix, but ugh.
//alert('you cannot edit this page! (also, please fix this stupid alert)');
}
editsummOriginalSummary = editsummOriginalSummary.value;
// For convenience, add a dropdown box with some canned edit summaries to the form.
var dropdown = document.createElement("select");
dropdown.style.width = "38%";
dropdown.style.margin = "0 4px 8px 0";
dropdown.onchange = editsummOnCannedSummarySelected;
editsummAddCatToDropdown(dropdown, "Custom edit summary presets");
for (var ixv = 0; ixv < customEditSummaryPresets.length; ixv++) {
editsummAddOptionToDropdown(dropdown, customEditSummaryPresets[ixv]);
}
var theParent = insertBeforeThis.parentNode;
theParent.insertBefore(dropdown, insertBeforeThis);
}
// unclear, but I *think* this is the end of the custom edit summary presets part