-
Notifications
You must be signed in to change notification settings - Fork 3
/
triggerError.js
114 lines (95 loc) · 3.54 KB
/
triggerError.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
108
109
110
111
112
113
114
// <!-- to show that alert box -->
const mn = document.getElementById('main');
const warning_title = document.getElementById('warning_title');
const warning_detail = document.getElementById('warning_detail');
const err_box = document.getElementById('errBox');
function activate_error_box(fire, gas) {
if (fire || gas) {
mn.style.cssText = 'filter: blur(2px)';
err_box.style.display = 'flex';
if (fire && gas) {
warning_title.innerHTML = "Fire and Harmful Gases ";
warning_detail.innerHTML = "Fire and Harmful gases is Detected in your house Evacuate!!";
showNotification("Emergency Alert!", "Elevated levels of harmful gases and fire have been detected in your residence. Please evacuate immediately for your safety!”");
}
else if (fire) {
warning_title.innerHTML = "Fire🔥";
warning_detail.innerHTML = "Fire Detected in your house Evacuate!!";
showNotification("Fire Emergency!", "Fire is detected at your residence!! Evacuate immediately for your safety ");
}
else if (gas) {
warning_title.innerHTML = "Gas";
warning_detail.innerHTML = "Harmful Gases are detected. Evacuate immedately !!";
showNotification("Gas Emergency!", "Harmful Gases are detected !! Evacuate immediately ");
}
}
else {
mn.style.cssText = 'filter: none';
err_box.style.display = 'none'
warning_title.innerHTML = "";
warning_detail.innerHTML = "";
}
return true;
}
// <!-- Notification script: -->
// Request permission to show notifications when the page is loaded
document.addEventListener('DOMContentLoaded', function() {
if ("Notification" in window) {
Notification.requestPermission().then(function (permission) {
if (permission !== "granted") {
console.log("Permission to show notifications denied");
}
});
} else {
console.log("Notifications not supported");
}
});
// Function to show a notification
function showNotification(title, message) {
// Check if notifications are supported by the browser
if (!("Notification" in window)) {
console.log("Notifications not supported");
return false;
}
// Check if permission to show notifications is granted
if (Notification.permission !== "granted") {
console.log("Permission to show notifications denied");
return false;
}
// Show the notification
new Notification(title, {
body: message
});
return true;
}
/*
function showNotification(title, message) {
// Check if notifications are supported by the browser
if (!("Notification" in window)) {
console.log("Notifications not supported");
return false;
}
// Check if permission to show notifications is granted
if (Notification.permission !== "granted") {
Notification.requestPermission().then(function (permission) {
if (permission !== "granted") {
console.log("Permission to show notifications denied");
return false;
} else {
// Show the notification
new Notification(title, {
body: message
});
return true;
}
});
} else {
// Show the notification
new Notification(title, {
body: message
});
return true;
}
}
*/
// showNotification("Fire Detected", "Fire Detected in your house. Evacuate!!");