Skip to content

Instantly share code, notes, and snippets.

@Nully
Created June 8, 2012 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nully/2893656 to your computer and use it in GitHub Desktop.
Save Nully/2893656 to your computer and use it in GitHub Desktop.
天気予報Rule
// 以下設定 ===================================================================================
// 開始時刻と終了時刻(hh:mmからhh:mmの間)
var times = {
start: { h: '14', m: '00' },
end: { h: '16', m: '00' }
},
// 通知時刻のインターバル(1時間単位)
interval = 1,
// 天気予報を見たいURL(スマフォ対応してるページとか便利よね!)
weather_url = 'http://weather.livedoor.com/lite/';
// 設定ここまで ===============================================================================
var today = new Date(),
year = today.getFullYear(),
month = today.getMonth(),
day = today.getDate(),
// スケジュール開始時間
scheduleStartTime = new Date(year, month, day, times.start.h, times.start.m),
// スケジュール終了時間
scheduleEndTime = new Date(year, month, day, times.end.h, times.end.m),
// スケジュールインターバル
scheduleInterval = 1000 * 60 * 60 * interval
;
// 通知のエイリアス
var ntf = device.notifications.createNotification("");
// スヌーズの設定
function snooze() {
// ntf.createNotification("OK?").show();
device.ajax({
url: weather_url,
type: 'GET',
headers: {
'Content-Type': 'text/html'
}
}, function onSUccess(body, textStatus, response){
ntf.content = '新しい天気予報だよ!';
ntf.on("click", function(){
device.browser.launch(weather_url);
});
ntf.show();
}, function onError(){
});
}
// スケジューラーの設定
device.scheduler.setTimer({
name: 'weatherCheck',
time: scheduleStartTime.getTime(),
interval: scheduleInterval,
exact: true
}, function(){
console.log('start timer');
snooze();
});
device.scheduler.setTimer({
name: 'deleteWeatherChecker',
time: scheduleEndTime.getTime(),
interval: 'day',
exact: true
}, function(){
console.log("remove timer");
device.scheduler.removeTimer("weatherCheck");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment