User:Bosco/Unsigned helper.js: Difference between revisions

From Test Wiki
Content deleted Content added
 
implement automatic edit summary
Line 8: Line 8:
ts=h+':'+m+', '+ts.getUTCDate()+' '+UnsignedHelper.months[ts.getUTCMonth()]+' '+ts.getUTCFullYear()+' (UTC)';
ts=h+':'+m+', '+ts.getUTCDate()+' '+UnsignedHelper.months[ts.getUTCMonth()]+' '+ts.getUTCFullYear()+' (UTC)';
return '\x7b\x7bsubst:'+template+'|'+user+'|'+ts+'\x7d\x7d';
return '\x7b\x7bsubst:'+template+'|'+user+'|'+ts+'\x7d\x7d';
},
appendToEditSummary:function(newSummary) {
const editSummaryField = $("#wpSummary:first");
if(editSummaryField.length==0) {
console.warn('Cannot find edit summary text field.');
return;
}
const oldText = editSummaryField.val().replace(/\s+$/, ""); // get text without trailing whitespace
let newText = "";
if (oldText.match(/[*]\/$/)) { // check if "/* section name */" is present
newText = text + " " + newSummary;
} else if (oldText.length!=0) {
newText = oldText + ", " + newSummary;
} else {
newText = newSummary;
}
editSummaryField.val(newText);
},
},


Line 71: Line 89:
e.value=tt+e.value.substr(pos);
e.value=tt+e.value.substr(pos);
$(e).textSelection('setSelection', { start:tt.length });
$(e).textSelection('setSelection', { start:tt.length });
UnsignedHelper.appendToEditSummary(`unsigned [[Special:Diff/${revid}]]`);
dialog.dialog('close');
dialog.dialog('close');
}
}