User:Dixtosa/autoSummary.js
Note – after saving, you may have to bypass your browser’s cache to see the changes.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- This script lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • redirects • your own
function GenerateSummary(){
let oldText = $("#wpTextbox1").text().split("\n");
let newText = $("#wpTextbox1").val().split("\n");
let diff = newText.filter((val, ind) => oldText.indexOf(val) == -1).join(";");
let oldSummary = $("#wpSummary").val();
$("#wpSummary").val(oldSummary + diff);
}
autoSummaryConfig = window.autoSummaryConfig || {insertAutomatically: true};
$(function(){
//$("#wpSummaryLabel").after($("<button type='button'>Insert auto summary</button>").css("border", "1px solid black").click(GenerateSummary));
if (autoSummaryConfig.insertAutomatically === true)
$("#wpSave").click(() => {
if ((/^\/\*.*?\*\/ $/.test($("#wpSummary").val()) || $("#wpSummary").val() === "")
&& (["", "Project"].indexOf(mw.config.values.wgCanonicalNamespace) >= 0))
GenerateSummary();
});
});