Skip to content

Instantly share code, notes, and snippets.

@ianchanning
Last active October 13, 2015 18:28
Show Gist options
  • Save ianchanning/c635fc5779f13bb7867a to your computer and use it in GitHub Desktop.
Save ianchanning/c635fc5779f13bb7867a to your computer and use it in GitHub Desktop.
(function($) {
jQuery.fn.chker = function() {
var timer = $(this);
var timerId = 0;
var tickInterval = 1000;
var dd = timer.find('.day');
var hh = timer.find('.hr');
var mm = timer.find('.min');
var ss = timer.find('.sec');
var hs = timer.find('.hsec');
var start = timer.find('.start');
var stop = timer.find('.stop');
var quotes = [
'Split \'em open like a can of beans',
'Fulham lost...again ',
'This is rowing, not farming',
'Do some Damage!',
'Give it some beans!',
'Keep it ticking over',
'This is unreal!',
'1 hour ergos, its money in the bank!',
'I used to be a hard man!',
'No. No. No. Thats it! No. No. No.',
'Technique.'
];
Notification.requestPermission();
var randomNotification = function() {
var randomQuote = quoteChooser();
var options = {
body: randomQuote
} ;
var n = new Notification('Bill says',options);
setTimeout(n.close.bind(n), 4000);
};
var quoteChooser = function() {
var randomNumber = Math.floor(Math.random() * 11);
quote = quotes[randomNumber];
return quote;
};
start.click(function() {
// prevent spamming the link
if (timerId === 0) {
timerId = setInterval(chkIt, tickInterval);
timer.addClass('ticking');
}
});
stop.click(function() {
clearInterval(timerId);
timerId = 0;
timer.removeClass('ticking');
});
var chkIt = function() {
// rubiks cube stopwatch (tickInterval = 10)
// chk.init().up(hs, 100).up(ss, 60);
// 100/th second year (tickInterval = 10)
// chk.init().up(hs, 100).up(ss, 60).up(mm, 60).up(hh, 24).up(dd, 365);
// egg timer
// chk.init().down(ss, 60).down(mm, 5);
// t-minus 10, 9, 8, ...
// chk.init().down(ss, 10).down(mm, 0);
// pomodoro timer
$(this).chk().down(ss, 60).down(mm, 25).up(dd, 100, randomNotification);
document.title = timer.find('p').text();
};
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment