Guest User

BukkitAlert -- UserScript port

a guest
Oct 21st, 2012
34
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        BukkitAlert
  3. // @namespace   http://forums.bukkit.org/threads/chrome-bukkitalert-get-notified-of-new-alerts-in-bukkit-anywhere.86294/page-5#post-1382207
  4. // @include     *
  5. // @version     1
  6. // ==/UserScript==
  7.  
  8. var xhr;
  9. var unread = 0;
  10. var con_unread = 0;
  11.  
  12. function notify(un) {
  13.     if (un == 1)
  14.     {
  15.         alert("1 new bukkit alert!");
  16.     }
  17.     else
  18.     {
  19.         alert(un + " new bukkit alerts!");
  20.     }
  21. }
  22.  
  23. function notify_con(un) {
  24.     if (un == 1)
  25.     {
  26.         alert("1 new bukkit message!");
  27.     }
  28.     else
  29.     {
  30.         alert(un + " new bukkit messages!");
  31.     }
  32. }
  33. var d = new Date();
  34. var seconds = d.getTime() / 1000;
  35. var diff = seconds - GM_getValue("lastDone",0);
  36.  
  37. if (diff > 300)
  38. {
  39.     GM_xmlhttpRequest({
  40.   method: "GET",
  41.   url: "http://www.bukkit.org/.json",
  42.   onload: function(xff) {
  43.     var xml = xff.responseText;
  44.      unread = JSON.parse( xml )._visitor_alertsUnread;
  45.     con_unread = JSON.parse( xml )._visitor_conversationsUnread;
  46.     if (unread > 0) {
  47.                 notify(unread);
  48.     }
  49.     if (con_unread > 0) {
  50.                 notify_con(con_unread);
  51.         }
  52.        
  53.     var seconds = d.getTime() / 1000;
  54.  
  55.     GM_setValue("lastDone", parseInt(seconds));
  56.    
  57.   }
  58. });
  59.    
  60.    
  61. }
RAW Paste Data