User:Mesidast/Fix ITN Talk.js

// Script by User:Mesidast to fix ITN Talk templates // Version 2.2

if (ITNautoSummary == null) var ITNautoSummary = true; //generate a short summary if (ITNshowDiff == null) var ITNshowDiff = true; //show diff after pressing button if (ITNmarkMinor == null) var ITNmarkMinor = true; //mark as minor

function ITN_Fix { var textbox = $("#wpTextbox1"); var summary = $("#wpSummary"); if ( !textbox ) { return false; }	var txt = textbox.val; var original = txt; txt = txt.replace(/\{\{ITN talk *\| *([0-9]{1,2}) *\| *([a-zA-Z]+) *\| *([0-9]{4}) *\| *oldid\d*=([0-9]+) *[^}]*\}\}/g, ""); txt = txt.replace(/(\{\{ITN talk[\S ]*\}\})\n{1}(\{\{[T|t]alk header[\S ]*\}\})/g, "$2\n$1"); // Only insert the edit summary when something has changed if (txt !== original) { textbox.val(txt); if (ITNautoSummary) summary.val(ITN_EditSummary(summary.val)); if (ITNmarkMinor) document.editform.wpMinoredit.checked = true; if (ITNshowDiff) $("#wpDiff").click; } }

function ITN_EditSummary(sum) { var ITNsum = "Fix ITN parameters"; if (sum.indexOf(ITNsum) == -1) { if (sum.match(/[^\*\/\s][^\/\s]?\s*$/)) { sum += " | "; }		sum += ITNsum; }	return sum; }

$(function {	if(document.forms.editform) {		mw.util.addPortletLink('p-tb', 'javascript:ITN_Fix', 'Fix ITN Talk', 'ca-formatcitations', 'Fix old ITN talk date parameters');	} });