This repository was archived by the owner on Oct 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
181 lines (167 loc) · 6.94 KB
/
index.html
File metadata and controls
181 lines (167 loc) · 6.94 KB
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
180
181
---
layout: largePage
column: headers/homepage_header.html
color: is-dark
---
<nav class="level">
<link rel="stylesheet" href="/css/odometer-theme-default.css">
<script src="/js/odometer.min.js"></script>
<script>
if (!'serviceWorker' in navigator || !Notification){
document.querySelectorAll(".fb").forEach(i.remove())
}
</script>
<script class="fb" src="https://www.gstatic.com/firebasejs/5.0.4/firebase-app.js"></script>
<script class="fb" src="https://www.gstatic.com/firebasejs/5.0.4/firebase-messaging.js"></script>
<script>
// Initialize Firebase
var config = {
messagingSenderId: "463922476306"
};
if ('serviceWorker' in navigator && Notification){
firebase.initializeApp(config);
}
</script>
<script>
var messaging;
if ('serviceWorker' in navigator && Notification){
messaging = firebase.messaging();
}
var clicked = false
var apiInfo
var registration
if ('serviceWorker' in navigator && Notification){
navigator.serviceWorker.register('./js/sw.js')
.then((reg) => {
registration = reg
})
}
function startNotify(){
if (clicked == true){return}
if (!registration){return}
clicked = true;
messaging.useServiceWorker(registration);
messaging.usePublicVapidKey("BCxxHT6X2wLNVw1xroAiyzmp_qOXqwlV9KHgSa8Wlh_Xh3NURh4TkjKbmLwhylkDJmK2_M_-nNRtdCHVJ5fVeWg")
messaging.requestPermission().then(function() {
console.log('Notification permission granted.');
messaging.getToken().then(function(currentToken) {
if (currentToken) {
console.log(currentToken)
$.post("https://api.discordspark.com/push", {token: currentToken})
.done(() => {
return $("#stats-version").html(apiInfo.version + " <i id=\"bell\" class=\"fas fa-bell\"></i><i class=\"fas fa-check\" style=\"color: #32CD32\"data-fa-transform=\"shrink-3 left-8 down-7\"></i>")
})
.fail(e => {
console.log(e)
return $("#stats-version").html(apiInfo.version)
})
} else {
console.log('No Instance ID token available. Request permission to generate one.');
return $("#stats-version").html(apiInfo.version)
}
}).catch(function(err) {
console.log('An error occurred while retrieving token. ', err);
return $("#stats-version").html(apiInfo.version)
});
}).catch(function(err) {
console.log('Unable to get permission to notify.', err);
});
}
document.addEventListener('DOMContentLoaded', function() {
stats_gh = new Odometer({
el: document.getElementById("stats-gh"),
value: 0,
});
stats_downloads = new Odometer({
el: document.getElementById("stats-downloads"),
value: 0,
});
$.get("https://api.discordspark.com/stats", function(data) {
stats_gh.update(data.github);
stats_downloads.update(data.downloads);
apiInfo = data
$("#stats-version").attr("style", "font-size: 24px;")
var a = $("#stats-version").html(data.version + " <i id=\"bell\" onclick=\"startNotify()\" class=\"fas fa-bell\"></i>").promise()
if ('serviceWorker' in navigator == false || !Notification){
return $("#stats-version").html(data.version + " " )
}
a.then(() => {
if (Notification && Notification.permission == "granted"){
$("#stats-version").html(data.version + " <i id=\"bell\" class=\"fas fa-bell\"></i><i class=\"fas fa-check\" style=\"color: #32CD32\"data-fa-transform=\"shrink-3 left-8 down-7\"></i>")
messaging.onMessage(payload => {
console.log(payload)
var notificationTitle = payload.data.title;
var body = payload.data.body + "\nClick here for more information."
var notificationOptions = {
body,
icon: '/icons/Spark-icon-no-bg.png',
actions: (null || payload.data.actions)
};
var myNotification = new Notification(notificationTitle, notificationOptions)
myNotification.onclick = (e) => {
console.log(e)
myNotification.close()
if (window.location.toString().includes("beta")){
window.location = "https://beta.discordspark.com/releases"
}else{
window.location = "https://discordspark.com/releases"
}
}
setTimeout(() => {myNotification.close()}, 30000)
})
}
})
}, "json")
})
function askPermission() {
return new Promise(function(resolve, reject) {
const permissionResult = Notification.requestPermission(function(result) {
resolve(result);
});
if (permissionResult) {
permissionResult.then(resolve, reject);
}
})
.then(function(permissionResult) {
if (permissionResult !== 'granted') {
throw new Error('We weren\'t granted permission.');
}
});
}
</script>
<div class="level-item has-text-centered">
<div>
<p class="heading">Stargazers</p>
<div id="stats-gh"><i class="fas fa-spin fa-spinner"></i></div>
</div>
<br>
<a class="github-button" href="https://github.com/Spark-Core/spark" data-size="large" data-icon="octicon-star" aria-label="Star Spark-Core/spark on GitHub">Star</a>
</div>
<div class="level-item has-text-centered">
<div>
<p class="heading">Downloads</p>
<div id="stats-downloads"><i class="fas fa-spin fa-spinner"></i></div>
</div>
</div>
<div class="level-item has-text-centered">
<div>
<p class="heading">Version</p>
<div id="stats-version"><i class="fas fa-spin fa-spinner"></i></div>
</div>
</div>
<script async defer src="https://buttons.github.io/buttons.js"></script>
<style>
@media screen and (min-width: 1024px) {
iframe {
position: relative;
top: 50px;
left: -67px;
}
}
@media screen and (max-width: 1024px){
iframe {
display: none
}
}
</style>
</nav>