Skip to content

Instantly share code, notes, and snippets.

@chris-gunawardena
Created October 24, 2013 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-gunawardena/7132564 to your computer and use it in GitHub Desktop.
Save chris-gunawardena/7132564 to your computer and use it in GitHub Desktop.
Chrome plugin / grease monkey script to add a timer to JIRA for Agile stand ups.
// ==UserScript==
// @match https://*/secure/RapidBoard.jspa?rapidView=*
// @name Agile standup timer for JIRA - Chris Gunawardena
// ==/UserScript==
function addJQuery(callback) { //http://stackoverflow.com/questions/2246901/how-can-i-use-jquery-in-greasemonkey-scripts-in-google-chrome
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
addJQuery(function(){ //jquery loaded
jQuery( document ).ready( function( ){ //page loaded
setTimeout( function() { //wait 1 sec for JIRA ajax stuff to load
jQuery('#ghx-pool .ghx-swimlane-header .ghx-heading').each( function(i, ghx_heading){ //get all team member name headings
var time_limit = 60;//time per team member
var timer = jQuery( ' <span> ' + time_limit + ' seconds </span> ' );
jQuery(ghx_heading).append( jQuery( timer ) );
var start_stop_btn = jQuery( ' <strong> start </strong> ' );
jQuery(ghx_heading).append( jQuery( start_stop_btn ) );
start_stop_btn.on('click', function(){
switch( jQuery(start_stop_btn).text() )
{ case ' start ':
jQuery(start_stop_btn).text(' stop ');
timer_start();
break;
case ' stop ':
jQuery(start_stop_btn).text(' clear ');
timer_stop();
break;
case ' clear ':
jQuery(start_stop_btn).text(' start ');
time_limit = 60; //reset time
timer.text( time_limit +' seconds ');
$( ghx_heading ).stop().css("color", "#000");
break;
}
});
var set_interval;
var timer_start = function(){
set_interval = setInterval( timer_tick, 1000 );
};
var timer_stop = function(){
clearInterval( set_interval );
};
var timer_tick = function(){
time_limit--;
timer.text( time_limit +' seconds ');
if( time_limit < 0 )
{ $( ghx_heading ).stop().css("color", "#ff0000").animate({ color: "#000"}, 1000);
}
};
});
}, 1000);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment