User:Topaz/beta.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

topaz.usermessagewatcher = new Object();

topaz.usermessagewatcher.oldonload = window.onload;
window.onload = function() {
  if (typeof topaz.usermessagewatcher.oldonload == "function") topaz.usermessagewatcher.oldonload();
  topaz.usermessagewatcher.notifying = false;
  topaz.util.cookie.set("topaz.usermessagewatcher.lastcheck", topaz.util.time());
  var divlist = topaz.util.getobj("bodyContent").getElementsByTagName("div");
  if (divlist[1] && divlist[1].className=="usermessage" ||
      divlist[2] && divlist[0].className=="tz-primarySection" && divlist[2].className=="usermessage") {
    topaz.usermessagewatcher.setnotify(1);
  } else {
    topaz.usermessagewatcher.setnotify(0);
  }
};

topaz.usermessagewatcher.setnofity = function(enabled) {
  if (enabled == topaz.usermessagewatcher.notifying) return;
  topaz.usermessagewatcher.notifying = enabled;
  topaz.util.cookie.set("topaz.usermessagewatcher.hasnew", enabled);
  if (enabled) {
    alert("topaz.usermessagewatcher: new messages");
  } else {
    alert("topaz.usermessagewatcher: NO new messages");
  }
};

topaz.usermessagewatcher.update = function() {

};

setInterval("topaz.usermessagewatcher.update()", 5000);


var req = topaz.util.xmlhttpreq();
req.open("GET", "http://en.wikipedia.org/wiki/MediaWiki:Blank", true);
req.onreadystatechange = function() {
  if (req.readyState != 4) return;
  if (req.responseText.indexOf('<div class="usermessage">You have')!=-1) {
    //alert("new messages!");
  } else {
    //alert("zero new");
  }
};
req.send(null);