Skip to content

Instantly share code, notes, and snippets.

@EddM
Created August 30, 2009 11:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EddM/177944 to your computer and use it in GitHub Desktop.
Save EddM/177944 to your computer and use it in GitHub Desktop.
// ==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 = "http://www.rememberthemilk.com/atom/eddm/0123456/"
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