User:Dixtosa/autoSummary.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

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.

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();
		});
});