-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
179 lines (161 loc) · 5.14 KB
/
index.php
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Progressive Web App Template</title>
<meta name='description' content='PWA Template'>
<meta name='author' content='Mark Hewitt www.mh1.co'>
<meta name='robot' content='noindex, nofollow' />
<meta name='theme-color' content='#2e3135'>
<!-- Add to home screen for Safari on iOS -->
<meta name='apple-mobile-web-app-capable' content='yes'>
<meta name='apple-mobile-web-app-status-bar-style' content='black'>
<meta name='apple-mobile-web-app-title' content='PWA Template'>
<link rel='apple-touch-icon' href='/assets/images/launcher-icon-3x.png'>
<meta name='msapplication-TileImage' content='/assets/images/launcher-icon-3x.png'>
<meta name='msapplication-TileColor' content='#2e3135'>
<link rel='manifest' href='/manifest.json'>
<link rel='stylesheet' type='text/css' href='/assets/css/style.css'>
</head>
<body>
<div class='logo'>
<div class='beginning'>SMS</div>
<div class='loader'>
<div class='blue'>
<div class='red'></div>
</div>
</div>
<div class='ending'>group</div>
</div><br>
<?=time()?>
<button type="button" onclick="registerOneTimeSync()">One Time Sync</button>
<div class='offline-banner'>You are currently offline. While you can view your data, you cannot edit it. Please reconnect to a network in order to proceed.</div>
<script>
/* SERVICE WORKER - REQUIRED */
if ('serviceWorker' in navigator)
{
navigator.serviceWorker
.register('./sw.js')
.then(function(reg) {
console.log("ServiceWorker registered ◕‿◕", reg);
})
.catch(function(error) {
console.log("Failed to register ServiceWorker ಠ_ಠ", error);
});
}
function registerOneTimeSync() {
if (navigator.serviceWorker.controller) {
navigator.serviceWorker.ready.then(function(reg) {
if (reg.sync) {
reg.sync.register({
tag: 'oneTimeSync'
})
.then(function(event) {
console.log('Sync registration successful', event);
})
.catch(function(error) {
console.log('Sync registration failed', error);
});
} else {
console.log("Onw time Sync not supported");
}
});
} else {
console.log("No active ServiceWorker");
}
}
/* OFFLINE BANNER */
function updateOnlineStatus()
{
var d = document.body;
d.className = d.className.replace(/\ offline\b/,'');
if (!navigator.onLine)
{
d.className += " offline";
}
}
updateOnlineStatus();
window.addEventListener
(
'load',
function()
{
window.addEventListener('online', updateOnlineStatus);
window.addEventListener('offline', updateOnlineStatus);
}
);
/* CHANGE PAGE TITLE BASED ON PAGE VISIBILITY */
function handleVisibilityChange()
{
if (document.visibilityState == "hidden")
{
document.title = "Hey! Come back!";
}
else
{
document.title = original_title;
}
}
var original_title = document.title;
document.addEventListener('visibilitychange', handleVisibilityChange, false);
/* NOTIFICATIONS */
window.addEventListener('load', function ()
{
// At first, let's check if we have permission for notification
// If not, let's ask for it
if (window.Notification && Notification.permission !== "granted")
{
Notification.requestPermission(function (status)
{
if (Notification.permission !== status)
{
Notification.permission = status;
}
});
}
});
function notifyMe(alert_title, alert_body)
{
var options =
{
body: alert_body,
icon: 'assets/images/launcher-icon-4x.png',
}
// Let's check if the browser supports notifications
if (!("Notification" in window))
{
alert("This browser does not support system notifications");
return false;
}
// 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(alert_title,options);
return true;
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied')
{
Notification.requestPermission(function (permission)
{
// If the user accepts, let's create a notification
if (permission === "granted")
{
var notification = new Notification(alert_title,options);
return true;
}
});
}
// Finally, if the user has denied notifications and you
// want to be respectful there is no need to bother them any more.
console.log("Notifications denied");
return false;
}
//Usage:
//notifyMe("Title goes here", "Body text goes here");
</script>
</body>
</html>