-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
81 lines (72 loc) · 3.32 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Football News</title>
<meta name="description" content="Football News" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="css/materialize.min.css" />
<link rel="manifest" href="/manifest.json" />
<link rel="apple-touch-icon" href="/icon3.png">
<meta name="theme-color" content="#0091ea" />
<link href="/css/style.css" rel="stylesheet" />
</head>
<body>
<!-- Navigasi -->
<nav class="light-blue accent-4" role="navigation">
<div class="nav-wrapper container">
<a href="#" class="brand-logo" id="logo-container">Football News</a>
<a href="#" class="sidenav-trigger" data-target="nav-mobile">☰</a>
<ul class="topnav right hide-on-med-and-down"></ul>
<ul class="sidenav" id="nav-mobile"></ul>
</div>
</nav>
<!-- Akhir Navigasi -->
<div class="container" id="body-content"></div>
<script src="js/materialize.min.js"></script>
<script src="js/idb.js"></script>
<script src="js/db.js"></script>
<script src="js/nav.js"></script>
<script src="js/api.js"></script>
<script src="/register-sw.js"></script>
<script>
// UBAH KODE WEB PUSH AGAR TERBACA oleh PUSH MANAGER
function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding)
.replace(/-/g, '+')
.replace(/_/g, '/');
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
}
// SET UP PUSH NOTIFICATION
navigator.serviceWorker.ready.then(() => {
if (('PushManager' in window)) {
navigator.serviceWorker.getRegistration().then(function(registration) {
registration.pushManager
.subscribe({
userVisibleOnly: true,
applicationServerKey: urlBase64ToUint8Array("BK-gFob_NWUpoRlZtVTEfz0U4nn_-HE3vR3_KjSmGqGl_cvRkSYzPwC3ZKZVyoX9RukwBtLB9I4cv28ex1y17OM")
}).then(function(subscribe) {
console.log('Berhasil melakukan subscribe dengan endpoint: ', subscribe.endpoint);
console.log('Berhasil melakukan subscribe dengan p256dh key: ', btoa(String.fromCharCode.apply(
null, new Uint8Array(subscribe.getKey('p256dh')))));
console.log('Berhasil melakukan subscribe dengan auth key: ', btoa(String.fromCharCode.apply(
null, new Uint8Array(subscribe.getKey('auth')))));
}).catch(function(e) {
console.error('Tidak dapat melakukan subscribe ', e.message);
});
});
}
});
// REQUEST API UNTUK PERTAMA KALI
document.addEventListener("DOMContentLoaded", () => {
const page = window.location.hash.substr(1);
});
</script>
</body>
</html>