Guest User

Untitled

a guest
Dec 20th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        reddit modqueue checker
  3. // @namespace       reddit_listen2
  4. // @description     checks modqueue, duh
  5. // @include     *.reddit.com/*
  6. // ==/UserScript==
  7.  
  8. (function(){
  9.     function check(p) {
  10.         if (checking)
  11.             return;
  12.         var last = JSON.parse(localStorage['modqueue_last_checked']||'{}');
  13.         var t = new Date().getTime();
  14.         if (t - last < p) {
  15.             show(JSON.parse(localStorage['modqueue_last_count']||'{}'));
  16.         } else {
  17.             req = new XMLHttpRequest();
  18.             req.onreadystatechange = display;
  19.             req.open("GET", "/r/mod/about/modqueue.json", true);
  20.             req.send(null);
  21.             mqalert.innerText += "*";          
  22.             checking = true;
  23.         }
  24.     }
  25.     //"/message/unread/.json?mark=false"
  26.  
  27.     function display() {
  28.         if (req.readyState === 4) {
  29.             checking = false;
  30.             if (req.status === 200) {
  31.                 n = JSON.parse(req.responseText).data.children.length;
  32.                 var t = new Date().getTime();
  33.                 show(n);
  34.                 localStorage['modqueue_last_count'] = JSON.stringify(n);
  35.                 localStorage['modqueue_last_checked'] = JSON.stringify(t);
  36.             } else {
  37.                 mqalert.innerText = "mq X";
  38.             }
  39.         }
  40.     }
  41.  
  42.     function show(n) {
  43.         if (n === 0) {
  44.             mqalert.style.color = def_color;
  45.             mqalert.style.fontWeight = def_weight;
  46.             mqalert.innerText = "mq 0";
  47.         } else {
  48.             mqalert.style.color = "orangered";
  49.             mqalert.style.fontWeight = "bold";
  50.             mqalert.innerText = "mq " + n;
  51.         }
  52.     }
  53.  
  54.     var modmail = document.getElementById("modmail");
  55.     var mqsep = document.createElement("span");
  56.     mqsep.className = "separator";
  57.     mqsep.innerText = "|";
  58.     modmail.parentNode.insertBefore(mqsep, modmail.nextSibling);
  59.  
  60.     var mqalert = document.createElement("a");
  61.     mqalert.id = "mqalert";
  62.     mqalert.href = "/r/mod/about/modqueue";
  63.     mqalert.innerText = "mq ";
  64.     mqsep.parentNode.insertBefore(mqalert, mqsep.nextSibling);
  65.  
  66.     var def_color = mqalert.style.color;
  67.     var def_weight = mqalert.style.fontWeight;
  68.     var checking = false;
  69.  
  70.     mqalert.addEventListener("mouseOver", function(){check(30000)});    //30 seconds
  71.  
  72.     check(360000);      //six minutes
  73. })();
Add Comment
Please, Sign In to add comment