MediaWiki:Gadget-CommentWatch.js
From Wikinews, the free news source you can write!
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins
//This is a very quick script that is not very good. Will make nicer later. YMMV with this. /*extern wgNamespaceNumber, wgPageName, sajax_init_object addOnloadHook */ if (wgNamespaceNumber === 0 || wgNamespaceNumber === 1 || wgNamespaceNumber === 102) { var cWatch = {}; //init obj cWatch.init = function () { var Page = "Comments:" + wgPageName; // default if (wgNamespaceNumber === 1) { Page = "Comments:" + wgPageName.split(":", 2)[1]; } else if (wgNamespaceNumber === 102) { Page = wgPageName.split(":", 2)[1]; } cWatch.watchComments = function () { var x; x = sajax_init_object(); // do nothing if we can't check if (!x) { return; } x.open("GET", "//en.wikinews.org/w/index.php?action=watch&title=" + Page, true); x.setRequestHeader("Pragma", "cache=yes"); x.setRequestHeader("Cache-Control", "no-transform"); x.onreadystatechange = function () { if (x.readyState === 4) { /* Start success*/ if (x.status === 200) { document.getElementById("siteNotice").innerHTML += ('Comment Page now watched' ); } else { document.getElementById("siteNotice").innerHTML += ('Auto comment page watch <b>failed</b>. <a href="//en.wikinews.org/w/index.php?action=watch&title=' + Page + '">Watch manually?</a>.' ); } if (document.getElementById("ca-watch").addEventListener) { document.getElementById("ca-watch").firstChild.removeEventListener("click", cWatch.watchComments, true); } else if (document.getElementById("ca-watch").firstChild.attachEvent) { document.getElementById("ca-watch").firstChild.detachEvent("onclick", cWatch.watchComments); } x = undefined; } } x.send(null); } if (document.getElementById("ca-watch")) { //In case we're already watching var watchTab = document.getElementById("ca-watch").firstChild; if (watchTab.addEventListener) { watchTab.addEventListener("click", cWatch.watchComments, true); } else if (watchTab.attachEvent) { watchTab.attachEvent("onclick", cWatch.watchComments); } else { document.getElementById("siteNotice").innerHTML += ('Auto comment page watch <b>failed</b>. <a href="//en.wikinews.org/w/index.php?action=watch&title=' + Page + '">Watch manually?</a>.' ); } } } //End cWatch.init if (document.getElementById("globalWrapper")) { //We're a load event cWatch.init(); } else { addOnloadHook(cWatch.init); } }
