-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
107 lines (98 loc) · 3 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
let current = true;
let message = "this is a test notification message ";
let title = "title";
function notifyMe() {
// 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
sendNotification();
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== "denied") {
Notification.requestPermission().then(function (permission) {
$('#notify').attr('title', 'please click allow for the website to send you notifications');
// If the user accepts, let's create a notification
if (permission === "granted") {
sendNotification();
}
});
} else {
alert(":( denied to send notification");
$('#notify').text("denied");
$('#notify').css('background', '#FF8066');
$('#notify').attr('disabled', true);
$('#notify').attr('title', 'please allow the website to send you notifications');
}
function sendNotification() {
const greeting = new Notification(title, {
body: message,
icon: './icon.png'
});
greeting.addEventListener('click', function () {
window.open('https://github.com/bethropolis/NotifyApiTest');
});
$('#notify').text("notified");
$('#notify').css('background', 'rgb(19, 196, 155) none repeat scroll 0% 0%');
$('#notify').attr('title', 'notification sent');
setTimeout(function(){
$('#notify').text("notify");
$('#notify').css('background', 'hsl(245, 84%, 68%)');
$('#notify').attr('title', 'notification ');
},2000)
}
}
function showOne(data) {
if (data) {
$('#notify').hide();
$('.data').show("slow");
} else {
$('.data').hide(1000);
$('#notify').show('slow');
}
current = !current;
}
$("#feedback").click(function () {
var fdbck = prompt("enter your feedback to the developer");
if (fdbck) {
try{
$.post('https://pushme.vercel.app/api/sendNotification', {
ContentType: "application/x-www-form-urlencoded",
code: "5ro94qxv1jv",
title: "feedback",
message: fdbck
}).done(function( data ) {
if (data.success) alert("feedback successfully sent");
});
}catch(e){
alert("there was an error sending feedback");
console.error(e.message);
}
} else {
alert("feedback arborted");
}
});
$("#edit").click(function () {
showOne(current);
});
$("#title").on("input", function () {
title = $("#title").val();
$("#save").attr('disabled', false);
});
$("#message").on("input", function () {
message = $("#message").val();
$("#save").attr('disabled', false);
});
$("#save").click(function () {
$("#save").attr('disabled', true);
title = $("#title").val();
message = $("#message").val();
showOne(current);
});
$("#notify").click(function () {
$('#notify').text("notifying...");
notifyMe();
});