Skip to content

Instantly share code, notes, and snippets.

@agentlame
Created May 25, 2013 17:05
Show Gist options
  • Save agentlame/5649854 to your computer and use it in GitHub Desktop.
Save agentlame/5649854 to your computer and use it in GitHub Desktop.
Mod Queue Checker
// ==UserScript==
// @name Mod Queue Checker
// @version 1.0
// @namespace http://example.com
// @description Checks your unmoderated and mod queues.
// @match http://*.reddit.com/*
// @match https://*.reddit.com/*
// Author: Ictinus
// ==/UserScript==
var unmodqURL = '/r/mod/about/unmoderated'
var modqURL = '/r/mod/about/modqueue'
var unmodqSpan = 'unmoderatedChecker'
var modqSpan = 'modqChecker'
var redditUnmodChecker = {
version : 1.0,
init: function() {
var aMail = document.getElementById("modmail");
var spanCheckumq = document.createElement('span');
spanCheckumq.id = unmodqSpan;
spanCheckumq.innerHTML = "";
spanCheckumq.style.cursor = "pointer";
spanCheckumq.href = "#";
aMail.parentNode.insertBefore(spanCheckumq, aMail.nextSibling);
var spanCheckmq = document.createElement('span');
spanCheckmq.id = modqSpan;
spanCheckmq.innerHTML = "";
spanCheckmq.style.cursor = "pointer";
spanCheckmq.href = "#";
spanCheckumq.parentNode.insertBefore(spanCheckmq, spanCheckumq.nextSibling);
redditUnmodChecker.update();
},
addGlobalStyle : function(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
},
update: function() {
xhreq = new XMLHttpRequest;
xhreq.open("GET", unmodqURL + ".json", true);
xhreq.onreadystatechange = function () {
redditUnmodChecker.display(unmodqURL, unmodqSpan, xhreq);
};
xhreq.send();
xreq = new XMLHttpRequest;
xreq.open("GET", modqURL + ".json", true);
xreq.onreadystatechange = function () {
redditUnmodChecker.display(modqURL, modqSpan, xreq);
};
xreq.send();
},
display: function(url, span, req) {
var unmoderatedChecker = document.getElementById(span);
if(req.readyState == 4) {
if(req.status == 200) {
var resp=req.responseText;
var unmodJSON = JSON.parse(resp);
if (unmodJSON.data.children.length == 0) {
unmoderatedChecker.innerHTML = "";
} else {
unmoderatedChecker.innerHTML = " <span class='separator'>|</span><a class='" + span + "-link' href='" + url + "'>&nbsp;&nbsp;</a><span>" + unmodJSON.data.children.length + "</span>";
}
} else {
unmoderatedChecker.innerHTML = "<span class='separator'>|</span><a class='" + span + "-link' href='" + url + "'>¿</a>";
}
}
}
}
if (document.body) {
redditUnmodChecker.addGlobalStyle('a.' + unmodqSpan + '-link {width:20px; margin-right:-14px; margin-left:-5px; display: inline-block; position:relative; } span#' + unmodqSpan + ' {font-weight:bold; color: #369;}');
redditUnmodChecker.addGlobalStyle('a.' + modqSpan + '-link {width:20px; margin-right:-14px; margin-left:-5px; display: inline-block; position:relative; } span#' + modqSpan + ' {font-weight:bold; color: #FF4500;}');
redditUnmodChecker.init();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment