-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
102 lines (92 loc) · 3.72 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="theme-color" content="#00897B">
<meta name="Description" content="PWA, Progressive Web Application, Football, Dicoding, Dicoding Academy, CodePolitan">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Football PWA</title>
<link rel="manifest" href="manifest.json">
<link rel="icon" href="img/icon.png" sizes="256x256" type="image/png">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="materialize/css/materialize.min.css" media="screen,projection" />
<link type="text/css" rel="stylesheet" href="css/main.css"/>
</head>
<body>
<!-- Navigasi -->
<nav class="green">
<div class="nav-wrapper container">
<a href="#!" class="brand-logo">Football PWA</a>
<a href="#" data-target="nav-mobile" class="sidenav-trigger"><i class="material-icons">menu</i></a>
<ul class="topnav right hide-on-med-and-down"></ul>
<ul class="sidenav" id="nav-mobile"></ul>
</nav>
<!-- Akhir Navigasi -->
<!-- Isi Konten Dinamis -->
<div class="container" id="body-content">
<h5 class="header" id="header-title"></h5>
<div class="row">
<div class="center-align" id="loader"></div>
<div class="col s12 m12" id="main-content">
</div>
</div>
</div>
<!-- Akhir Isi Konten -->
<script type="text/javascript" src="materialize/js/materialize.min.js"></script>
<script type="text/javascript" src="js/idb.js"></script>
<script type="text/javascript" src="js/nav.js"></script>
<script type="text/javascript" src="js/api.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<!-- Inisialisasi plugin sidenav -->
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
var elems = document.querySelectorAll('.sidenav');
var instances = M.Sidenav.init(elems);
});
</script>
<script>
// Memeriksa API service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js').then(function () {
console.log('Pendaftaran ServiceWorker berhasil');
}, function () {
console.log('Pendaftaran ServiceWorker gagal');
});
navigator.serviceWorker.ready.then(function () {
console.log('ServiceWorker sudah siap bekerja.');
});
requestPermission();
} else {
console.log("ServiceWorker belum didukung browser ini.")
}
function requestPermission(){
if('Notification' in window) {
Notification.requestPermission().then(result => {
if(result === 'denied'){
console.log("Fitur notifikasi tidak diijinkan.");
return;
} else if (result === 'default'){
console.error("Pengguna menutup kotak dialog permintaan ijin.");
return;
}
console.log('Notification granted');
if(('PushManager' in window)) {
console.log('PushManager exist!');
navigator.serviceWorker.getRegistration().then(reg => {
reg.pushManager.subscribe({
userVisibleOnly: true
}).then(sub => {
console.log('Berhasil melakukan subscribe dengan endpoint:' + sub.endpoint);
console.log("p256dh: " + btoa(String.fromCharCode.apply(null, new Uint8Array(sub.getKey('p256dh')))));
console.log("auth: " + btoa(String.fromCharCode.apply(null, new Uint8Array(sub.getKey('auth')))));
}).catch(e => {
console.log('Error: ', e)
})
})
}
})
}
}
</script>
</body>
</html>