Forked from dlwr/patch.check.noncoffee.days.tbrl.js
Last active
November 20, 2017 01:48
-
-
Save taizooo/fb829f0d974bad281011 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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.2.1" | |
// , "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 URL = 'https://twitter.com/taizooo/status/782176967353262080'; | |
var URL = 'https://twitter.com/taizooo/status/931859502965518336' | |
var timer = null; | |
var interval = 60 * 60 * 1000; | |
function check_days_without_coffee() { | |
if (timer) { | |
clearTimeout(timer); | |
timer = null; | |
} | |
var today = new Date(); | |
if (today.getHours() === 9 || today.getHours() === 13 || today.getHours() === 17) { | |
// c.f. https://twitter.com/taizooo/status/932174318586314752 | |
var origin = new Date(2017, 10, 19); | |
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