User:Topaz/beta.js

This is an old revision of this page, as edited by Topaz (talk | contribs) at 01:44, 28 June 2007 (revert after debug). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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.
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);