A few suggestions and tweaks
![]() ![]() |
Nice work on this userscript. I just found it today after reinstalling my Lighthouse Fluid app. I made a few modifications to accomplish the following: * Get open tickets for all projects in account, not just a single project
Not sure if this will format correctly, but here are my revisions to your code. Feel free to revise your source code if you're interested.
(function () {
if (window.fluid) {
var updateInterval = 600000; // How often to check for new tickets in milliseconds
var min_request_delay = 50; // Pause between requests (milliseconds) to avoid rate limits
var API_KEY = 'XXXXXX'; // Lighthouse API key
function check_for_updates () {
var xhttp_projects = new XMLHttpRequest();
var totalOpenTickets = 0;
// get projects
xhttp_projects.onload = function() {
var xhttp_projects_xml = xhttp_projects.responseXML;
var projects = xhttp_projects_xml.getElementsByTagName("project");
var p = projects.length;
var i = 0;
function load_tickets() {
var project = projects[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
var xhttp_tickets = new XMLHttpRequest();
xhttp_tickets.onload = function() {
var xhttp_tickets_xml = xhttp_tickets.responseXML;
var projectOpenTickets = (xhttp_tickets_xml) ? xhttp_tickets_xml.getElementsByTagName("ticket").length : 0;
if (projectOpenTickets == 30) {
var loadNextPage = true;
var pageNumber = 2;
while (loadNextPage == true) {
var xhttp_more_tickets = new XMLHttpRequest();
xhttp_more_tickets.open("GET", "/projects/"+project+"/tickets.xml?q=responsible:me%20state:open&page="+pageNumber, false, API_KEY+":x");
xhttp_more_tickets.send("");
xhttp_more_tickets_xml = xhttp_more_tickets.responseXML;
var moreTickets = xhttp_more_tickets_xml.getElementsByTagName("ticket").length;
projectOpenTickets += moreTickets;
pageNumber++;
if (moreTickets < 30) {
loadNextPage = false;
}
}
}
totalOpenTickets += projectOpenTickets;
window.fluid.dockBadge = (totalOpenTickets) ? totalOpenTickets : 0;
}
xhttp_tickets.open("GET", "/projects/"+project+"/tickets.xml?q=responsible:me%20state:open", true, API_KEY+":x");
xhttp_tickets.send("");
if (i < p - 1) {
i++;
// Lighthouse doesn't like a bunch of requests at once
setTimeout(load_tickets, min_request_delay);
}
}
load_tickets();
};
xhttp_projects.open("GET", "/projects.xml", true, API_KEY+":x");
xhttp_projects.send("");
setTimeout(check_for_updates, updateInterval);
}
check_for_updates();
}
})();
Again, thanks for putting this together. |
![]() ![]() |
Thanks Jim, I'm currently using your code, slightly modified. I changed window.fluid.dockBadge = (totalOpenTickets) ? totalOpenTickets : 0; to window.fluid.dockBadge = (totalOpenTickets) ? totalOpenTickets : ""; Otherwise, it always shows a 0 badge if there are no open tickets. |

