Created
November 13, 2009 23:30
-
-
Save smathy/234262 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name LighthouseBadge | |
// @namespace http://fluidapp.com | |
// @description Adds a badge showing the number of open tickets assigned to you. | |
// @include * | |
// @author Adam Tucker http://adamjt.net | |
// ==/UserScript== | |
// How often to check for new tickets in milliseconds | |
var updateInterval = 300000; | |
var lh_api = "__YOUR__PERSONAL__API__KEY__"; | |
updateBadge(); | |
function updateBadge () { | |
xhttp=new XMLHttpRequest(); | |
// Customize this API call to your needs http://lighthouseapp.com/api | |
xhttp.open("GET","/tickets.xml?q=responsible%3Ame%20state%3Aopen", false, lh_api); | |
xhttp.send(""); | |
xmlDoc=xhttp.responseXML; | |
myOpenTickets = xmlDoc.getElementsByTagName("ticket").length; | |
if (myOpenTickets > 0 ) { | |
if (myOpenTickets == 30) { | |
loadNextPage = true; | |
pageNumber = 2; | |
while (loadNextPage == true) { | |
xhttp.open("GET","/tickets.xml?q=responsible%3Ame%20state%3Aopen&page=" + pageNumber, false, lh_api); | |
xhttp.send(""); | |
xmlDoc=xhttp.responseXML; | |
moreTickets = xmlDoc.getElementsByTagName("ticket").length; | |
myOpenTickets += moreTickets; | |
pageNumber++; | |
if (moreTickets < 30) { | |
loadNextPage = false; | |
} | |
} | |
} | |
window.fluid.dockBadge = myOpenTickets; | |
} | |
setTimeout(updateBadge, updateInterval); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment