From 78e823516c2b507a7847e08640ad689130bb617b Mon Sep 17 00:00:00 2001 From: Tim Windelschmidt Date: Sat, 5 Sep 2015 20:04:41 +0200 Subject: [PATCH] Added Browser Notifications --- node/public/js/notification.js | 74 ++++++++++++++++++++++++++++++++++ node/views/index.jade | 1 + 2 files changed, 75 insertions(+) create mode 100644 node/public/js/notification.js diff --git a/node/public/js/notification.js b/node/public/js/notification.js new file mode 100644 index 0000000..f4d87a2 --- /dev/null +++ b/node/public/js/notification.js @@ -0,0 +1,74 @@ +var Notification = window.Notification || window.mozNotification || window.webkitNotification; +var data; +var laststate; + +Notification.requestPermission(function (permission) { + // console.log(permission); +}); + +function showopen() { + var instance = new Notification( + "CTDO - Status", { + body: "Der Chaostreff Dortmund ist nun offen.", + icon: "/img/green.png" + } + ); + + instance.onclick = function () { + // Something to do + }; + instance.onerror = function () { + // Something to do + }; + instance.onshow = function () { + setTimeout(function(){ + instance.close(); + }, 3000); + }; + instance.onclose = function () { + // Something to do + }; +} + +function showclose() { + var instance = new Notification( + "CTDO - Status", { + body: "Der Chaostreff Dortmund ist nun geschlossen.", + icon: "/img/red.png" + } + ); + + instance.onclick = function () { + // Something to do + }; + instance.onerror = function () { + // Something to do + }; + instance.onshow = function () { + setTimeout(function(){ + instance.close(); + }, 3000); + }; + instance.onclose = function () { + // Something to do + }; +} + +window.setInterval(function(){ + $.getJSON("/api/simple/v2", function(data){ + var html = []; + + $.each(data, function(index, value){ + if (index == 'state' && value == false && laststate != false) { + laststate = false; + showclose(); + } + else if (index == 'state' && value == true && laststate != true) { + laststate = true; + showopen(); + }else { + // Nothing + } + }); + }); +}, 60000); diff --git a/node/views/index.jade b/node/views/index.jade index 7e8d222..ab7ba0b 100644 --- a/node/views/index.jade +++ b/node/views/index.jade @@ -58,3 +58,4 @@ block scripts script(type="text/javascript",src="/js/graph.js") script(type="text/javascript",src="/js/vendor/raphael.2.1.0.min.js") script(type="text/javascript",src="/js/vendor/justgage.1.0.1.min.js") + script(type="text/javascript",src="/js/notification.js")