From 6737962e64584d88c70314122c9a0921155ea401 Mon Sep 17 00:00:00 2001 From: Vaibhav Chanana Date: Fri, 21 May 2021 00:36:30 +0530 Subject: [PATCH 1/2] Added a notification toggle --- index.html | 8 ++++++++ js/init.js | 8 ++++++++ js/script.js | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/index.html b/index.html index 46247b4..1b999a6 100644 --- a/index.html +++ b/index.html @@ -116,6 +116,14 @@ + +
+
+ + +
+
+
diff --git a/js/init.js b/js/init.js index 5b6b109..2c59de3 100644 --- a/js/init.js +++ b/js/init.js @@ -24,6 +24,7 @@ const $relogin = $('#relogin') const $logout = $('#logout') const $ben = $('#ben') +const $notification = $('#notification') const $fetchDiv = $('#fetch-div') const $fetchLabel = $('#fetch-label') const $fetchingDiv = $('#fetching-div') @@ -59,6 +60,7 @@ $(document).ready(function () { $startFetch.click(startFetchSlots) $stopFetch.click(stopFetchSlots) $book.click(book) + $notification.click(toggleNotification) $('input[type=radio]').change(setPreferences) }) $fetchingDiv.hide() @@ -87,6 +89,8 @@ function play(msg, low=null) { const audio = new Audio(); audio.src = 'assets/alert.mp3' audio.play() + if(localStorage.getItem('notification')) + new Notification(msg) } const delay = (s) => new Promise((resolve) => setTimeout(resolve, s * 1000)) @@ -132,6 +136,10 @@ if (localStorage.getItem('fees')) $(`input#${localStorage.getItem('fees')}`).prop('checked', true) if (localStorage.getItem('mobile')) $mobile.attr('value', localStorage.getItem('mobile')) +if(Notification.permission !== 'granted') + localStorage.removeItem('notification') +if(localStorage.getItem('notification') && Notification.permission !== 'denied') + $notification.prop('checked', true) $(document).ready(async function () { token = localStorage.getItem('token') diff --git a/js/script.js b/js/script.js index 0589bff..9a6db74 100644 --- a/js/script.js +++ b/js/script.js @@ -306,3 +306,27 @@ async function download(appointment_id) { document.body.appendChild(link); link.click(); } + +async function toggleNotification() { + if(localStorage.getItem('notification')) { + localStorage.removeItem('notification') + $notification.prop('checked', false) + } else { + if ("Notification" in window) { + if (Notification.permission !== "denied") { + const permission = await Notification.requestPermission() + + if(permission === 'granted') { + $notification.prop('checked', true) + localStorage.setItem('notification', 'true') + new Notification('Notifcations Enabled') + } + } + } + } + + if(Notification.permission === 'denied') { + $notification.prop('checked', false) + alert('Permission Denied') + } +} \ No newline at end of file From dac46a3f4b8bb72ed19183c46ad9da8bf834d393 Mon Sep 17 00:00:00 2001 From: Neel Patel Date: Fri, 21 May 2021 20:10:28 +0530 Subject: [PATCH 2/2] Click on label to toggle --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 1b999a6..2b37dfa 100644 --- a/index.html +++ b/index.html @@ -120,7 +120,7 @@
- +