-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.js
36 lines (28 loc) · 1.01 KB
/
js.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
var goal = 1;
var subs = 0;
function calculateGoal () {
let progress = Math.floor((subs / goal) * 100);
let progressBar = document.getElementById('subProgress');
progressBar.style.width = progress + "%";
}
window.addEventListener('onEventReceived', function (obj) {
if (!obj.detail.event) return;
const listener = obj.detail.listener.split("-")[0];
if (listener === 'subscriber') {
//subs += obj.detail.event.amount;
// Only add one. Multiple gift subs trigger the regular sub event x times.
++subs;
calculateGoal();
}
});
window.addEventListener('onWidgetLoad', function (obj) {
let fieldData = obj.detail.fieldData;
let message = document.getElementById('message');
// Init goal
goal = fieldData.subGoal;
// Init goal message
message.innerText = fieldData.goalText;
// Get the initial number of subscribers
subs = obj["detail"]["session"]["data"]["subscriber-total"]["count"];
calculateGoal();
});