Skip to content

Instantly share code, notes, and snippets.

@geraintwhite
Last active August 29, 2015 14:21
Show Gist options
  • Save geraintwhite/5f6f00e3c427fd50af95 to your computer and use it in GitHub Desktop.
Save geraintwhite/5f6f00e3c427fd50af95 to your computer and use it in GitHub Desktop.
Pomodro tomato timer - Bash and JS versions
<!doctype html>
<html>
<head>
<title>Tomato Timer</title>
<script src="tomato.js"></script>
</head>
<body>
<button id="start">Start Timer</button>
<button id="stop">Stop Timer</button>
</body>
</html>
const WORK = 25 * 60 * 1000,
REST = 5 * 60 * 1000;
function notifyPermission (cb) {
if (!window.Notification) {
alert('This browser does not support system notifications');
} else if (Notification.permission === 'granted') {
if (cb) cb();
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (permission === 'granted') {
if (cb) cb();
}
});
}
}
function notify (message) {
notifyPermission(function () {
var n = new Notification('Tomato Timer', {
body: message,
icon: 'tomato.png'
});
setTimeout(n.close.bind(n), 5000);
});
}
window.onload = function () {
var timer;
notifyPermission();
document.getElementById('start').onclick = function () {
function loop () {
timer = setTimeout(function () {
notify('Take a break!');
timer = setTimeout(function () {
notify('Get back to work!');
loop();
}, REST);
}, WORK);
}
notify('Timer started');
loop();
};
document.getElementById('stop').onclick = function () {
notify('Timer stopped');
clearTimeout(timer);
};
};
#!/bin/bash
function tomato_msg() {
croutonnotify -i tomato.png -t "Tomato Timer" -m "$1"
}
while true; do
sleep $((25*60))
tomato_msg "Have a break!"
sleep $((5*60))
tomato_msg "Get back to work!"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment