forked from blackness3/Crisp_Telegram_Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv2board.js
83 lines (74 loc) · 2.41 KB
/
v2board.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
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
function formatDate(date) {
year = date.getFullYear();
month = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
day = date.getDate();
return year + '-' + month + '-' + day
}
function btogb(n) {
return (n / 1024 / 1024 / 1024).toFixed(2)
}
async function fetchUserDataFromUrl(url) {
const myHeaders = new Headers();
myHeaders.append("Authorization", localStorage.getItem("token"));
const requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
const response = await fetch(url, requestOptions);
const result = await response.json();
return result;
};
async function crispPush() {
fetchUserDataFromUrl('/api/v1/user/getSubscribe')
.then((result) => {
window.$crisp.push(
[
"set", "session:data", [
[
["Plan", (null === (o = result.data.plan) || void 0 === o ? void 0 : o.name) || "-"],
["ExpireTime", formatDate(date = new Date(result.data.expired_at * 1000))],
["UsedTraffic", btogb(result.data.u + result.data.d)],
["AllTraffic", btogb(result.data.transfer_enable)],
]
]
]
);
}
)
fetchUserDataFromUrl('/api/v1/user/info')
.then((result) => {
window.$crisp.push(["set", "user:email", result.data.email])
window.$crisp.push(
[
"set", "session:data", [
[
["Balance", result.data.balance / 100]
]
]
]
)
}
)
};
(function () {
function wait(time) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(time)
}, time)
})
}
(async () => {
for (var i = 0; i < 5; i++) {
if (document.querySelector('.cc-nsge') != null) {
document.querySelector('.cc-nsge').addEventListener('click', function handleClick(event) {
console.debug("try to add eventlistener " + i);
crispPush();
});
break
}
await wait(1000);
}
})();
})();