Skip to content

Instantly share code, notes, and snippets.

@dlwr
Forked from taizooo/patch.check.wedata.tbrl.js
Last active August 29, 2015 14:08
Show Gist options
  • Save dlwr/2f03e894672551072c38 to your computer and use it in GitHub Desktop.
Save dlwr/2f03e894672551072c38 to your computer and use it in GitHub Desktop.
// ==Taberareloo==
// {
// "name" : "Check how many days have passed without coffee"
// , "description" : "Check how many days have passed without coffee every coffee time(16:30) and tweet it"
// , "include" : ["background"]
// , "version" : "0.1.4"
// , "downloadURL" : "https://gist.github.com/dlwr/2f03e894672551072c38/raw/patch.check.noncoffee.days.tbrl.js"
// }
// ==/Taberareloo==
(function() {
var URL = 'https://twitter.com/taizooo/status/524925571046715393';
var timer = null;
var interval = 60 * 1000;
function check_days_without_coffee() {
if (timer) {
clearTimeout(timer);
timer = null;
}
var today = new Date();
if (today.getHours() === 16 && today.getMinutes() === 30) {
// c.f. https://twitter.com/taizooo/status/525059336813309953
var origin = new Date(2014, 9, 23);
var days = Math.floor(((today - origin) / (24 * 60 * 60 * 1000)) + 1);
TBRL.Notification.notify({
title: '禁コーヒー' + days + '日目',
message: days + 'days have passed without coffee',
onclick: function() {
chrome.tabs.create({
url: URL
});
this.close();
}
});
TBRL.Service.post({
type: 'regular',
description: '禁コーヒー' + days + '日目',
https: {
pageUrl: [false, URL]
}
}, Models['Twitter']);
}
timer = setTimeout(check_days_without_coffee, interval);
}
check_days_without_coffee();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment