User:Anne drew/WatchingIndicator.js
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(function () {
let saveButtonWatchingIndicator = document.getElementById('wpSave');
if (saveButtonWatchingIndicator) {
saveButtonWatchingIndicator.onmousedown = function(event) {
let watchBox = document.getElementById("wpWatchthis");
let textBox = document.getElementById('wpTextbox1');
if (textBox && watchBox) {
let watching = document.getElementById("ca-unwatch") || watchBox.checked ? "watching this page'>★" : "not watching this page'>☆";
let text = textBox.value;
if (text.search(/````/g) > -1) {
if (confirm("Replace ```` with signature and watching indicator?") && ((text.match(/````/g) || []).length == 1 || confirm("Multiple instances found. Continue?")))
textBox.value = text.replace(/````/g, "{{subst:3~}} <span style='color:#09F' title='I’m "+ watching + "</span> {{subst:5~}}");
}
}
}
}
})();