Skip to content

Instantly share code, notes, and snippets.

@strukturart
Created October 22, 2019 20:29
Show Gist options
  • Save strukturart/1ece928dd9dd75a19793ba579843627d to your computer and use it in GitHub Desktop.
Save strukturart/1ece928dd9dd75a19793ba579843627d to your computer and use it in GitHub Desktop.
function notify(param_title,param_text) {
var options = {
body: param_text
}
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification(param_title,options);
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== "denied") {
Notification.requestPermission().then(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification(param_title,options);
}
});
}
}
function remove_alarms()
{
var request = navigator.mozAlarms.getAll();
request.onsuccess = function () {
this.result.forEach(function (alarm) {
navigator.mozAlarms.remove(alarm.id);
});
};
request.onerror = function () {
console.log("An error occurred: " + this.error.name);
};
}
function set_alarm(alarm_date,message_text)
{
var alarm = {
date: new Date(alarm_date),
respectTimezone: 'ignoreTimezone',
data: {
"message":message_text
}
};
var request = navigator.mozAlarms.add(alarm.date, alarm.respectTimezone, alarm.data);
request.onsuccess = function () {
console.log('A new alarm has been set:' + this.result);
alarm.id = this.result; // get the id of the new alarm.
}
request.onerror = function () {
console.log('operation failed: ' + this.error);
}
}
navigator.mozSetMessageHandler("alarm", function (mozAlarm) {
var getData = JSON.stringify(mozAlarm.data)
if(mozAlarm.data["message"] == "Start")
{
notify("alarm","Start");
airplan_strict("off")
}
if(mozAlarm.data["message"] == "End")
{
notify("alarm","End");
airplan_strict("on")
}
});
set_alarm("Oct 22, 2019 21:32:00","Start")
set_alarm("Oct 22, 2019 21:35:00","End")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment