Skip to content

Instantly share code, notes, and snippets.

@omarramos
Created March 26, 2011 15:17
Show Gist options
  • Save omarramos/888358 to your computer and use it in GitHub Desktop.
Save omarramos/888358 to your computer and use it in GitHub Desktop.
Displays a dock badge for items in a certain Remember The Milk list.
// ==UserScript==
// @name Due Badge
// @namespace http://fluidapp.com
// @description Displays a dock badge for items in a certain Remember The Milk list.
// @include *
// @author Edd Morgan <trquadrant.com>
// ==/UserScript==
(function () {
if (window.fluid) {
// URL to your target list (could be a smart list) on RTM
var due_list_atom_url = "ATOM_FEED_HERE"
var timeout = 30; // Time, in seconds, between updates
function makeReq(url, callback) {
var request = new XMLHttpRequest();
request.open("POST", url, true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
if (request.responseText) {
handleResponse(request.responseText, callback);
}
}
}
request.send(null);
}
function handleResponse(response, callback) {
var parser = new DOMParser();
var doc = parser.parseFromString(response,"text/xml");
callback(doc.documentElement);
}
function parse(data) {
var items = data.getElementsByTagName('entry');
if(items.length > 0) {
window.fluid.dockBadge = "" + items.length + "";
} else {
window.fluid.dockBadge = null;
}
}
function loadfeed(url) {
makeReq(url, parse);
setTimeout(initRequest, timeout * 1000);
}
function initRequest() {
loadfeed(due_list_atom_url);
}
initRequest();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment