User:Mike.lifeguard/fixPaste.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
//Written and maintained by [[User:Mike.lifeguard]]
function pastemods(){
	var wpSummary = document.getElementById("wpSummary");
	if (!wpSummary) return false;
	text = wpSummary.value;
	var re = /\/\* (.*?) \*\/ ?\=\=\= ?(.*?) ?\=\=\=.*/i;
	if (re.test(text)){
		if (wgPageName.indexOf("Talk:Spam_blacklist/Archives/") != -1) {
			var newtext = text.replace(re, "/* $1 */ Archived section \"$2\" from [[Talk:Spam blacklist]]");
		} else {
			var newtext = text.replace(re, "/* $1 */ ===$2===");
		}
		wpSummary.value = newtext;
	}
}
function addpastemods() {
	form = document.getElementById('editform');
	if (!form) return false;
	addHandler(form,'submit',pastemods);
}
if (wgAction == "edit") addOnloadHook(addpastemods);