Skip to content

Instantly share code, notes, and snippets.

@M1ke
Last active February 26, 2024 07:15
Show Gist options
  • Save M1ke/4944552 to your computer and use it in GitHub Desktop.
Save M1ke/4944552 to your computer and use it in GitHub Desktop.
Script to add a timer to a page, along with a function to record it in a Trello comment.

Bookmark Timer

This was made because Trello is awesome but doesn't provide time tracking.

The core of the script is a basic timer object that creates a timer link using jQuery. It then hooks in a function to log the time as a comment on Trello. It's very basic at present; if you don't have a card open the timer will stop and not record, but it makes a nice auto-comment when you do stop the timer.

Chrome extension

Use the Bookmarklet2Chrome page to turn it into a convenient Chrome extension.

License

        DO WHAT THE F**K YOU WANT TO PUBLIC LICENSE
                Version 2, December 2004

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | WTFPL

  1. You just DO WHAT THE F**K YOU WANT TO.
javascript:(function(){
var jsCode=document.createElement('script');
jsCode.setAttribute('src','https://gist.github.com/M1ke/4944552/raw/17d5768dab89f3737104202b4fc7a56d286fc4c7/trello-timer.js');
document.body.appendChild(jsCode);
}());
var bookmarkTimer={
time:0
,timerStop:false
,start:function(){
this.time=-1;
this.continue();
}
,continue:function(){
bookmarkTimer.time+=1;
$('a.bookmark-timer strong').text(Math.floor(bookmarkTimer.time/60)+' min '+bookmarkTimer.time%60+'s');
if (!bookmarkTimer.timerStop) {
setTimeout(bookmarkTimer.continue,1000);
}
else {
bookmarkTimer.timerStop=false;
}
}
,stop:function(){
this.timerStop=true;
this.record();
}
,record:function() {
console.log(this.time)
}
,$setup:function(){
$('a.bookmark-timer').remove();
$('<a href="#" class="bookmark-timer"><span>Start timer</span> <strong></strong></a>').css({position:'fixed',top:0,left:0,'z-index':100,display:'block',padding:'5px',background:'#fff'}).bookmarkTimerClick().appendTo('body');
}
};
$.fn.bookmarkTimerClick=function(){
return this.click(function(e){
e.preventDefault();
if ($(this).hasClass('started')){
bookmarkTimer.stop();
$(this).removeClass('started').children('span').text('Start timer');
}
else {
bookmarkTimer.start();
$(this).addClass('started').children('span').text('Stop timer');
}
});
};
window.trelloTimer=function() {
bookmarkTimer.record=function() {
$('.new-comment').find('textarea.new-comment-input').val('Time recorded: '+Math.floor(this.time/60)+' min '+this.time%60+'s')
.end().find('input.js-add-comment').click();
return true;
};
bookmarkTimer.$setup();
};
window.trelloTimer();
@M1ke
Copy link
Author

M1ke commented Feb 14, 2013

Git revisions are causing a bit of an issue to the bookmarklet, as the raw filename changes with each revision. I'll see about hosting it elsewhere. Current bookmarklet is updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment