MediaWiki:Gadget-CommentWatch.js

try { // containerize gadget, to protect other gadgets if this one goes wrong

//This is a very quick script that is not very good. Will make nicer later. YMMV with this. /*extern sajax_init_object */ if (mw.config.get('wgNamespaceNumber') === 0 || mw.config.get('wgNamespaceNumber') === 1 || mw.config.get('wgNamespaceNumber') === 102) { var cWatch = {}; //init obj

cWatch.init = function { var Page = "Comments:" + mw.config.get('wgPageName'); // default if (mw.config.get('wgNamespaceNumber') === 1) { Page = "Comments:" + mw.config.get('wgPageName').split(":", 2)[1]; } else if (mw.config.get('wgNamespaceNumber') === 102) { Page = mw.config.get('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 failed. Watch manually?.' ); }   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 failed. Watch manually?.' ); } }

} //End cWatch.init

if (document.getElementById("globalWrapper")) { //We're a load event cWatch.init; } else { $(cWatch.init); } }

} catch (e) { // containerize gadget, to protect other gadgets if this one goes wrong // ignore }