-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
145 lines (126 loc) · 5.04 KB
/
index.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
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
import { log, warn, error } from "./src/utils/themeLog.js"
import { serverDomain } from "./src/config/serverDomain.js"
let currentTime = window.DataStore.get("start-time", Date.now())
class CheckDomainExpiry {
main = () => {
let expiringTime = new Date(serverDomain.expiring);
let timeDifference = expiringTime - currentTime;
let daysDifference = timeDifference / (1000 * 60 * 60 * 24);
if (daysDifference < 30) {
alert(`The server domain is expiring soon! (${daysDifference} days left)`);
warn(`The server domain is expiring soon! (${daysDifference} days left)`)
}
else {
log(`Server domain expiry in ${daysDifference} days`);
}
};
}
const checkDomainExpiry = new CheckDomainExpiry()
class CheckUsing {
constructor () {
this.generateTempID = Math.floor(100 + Math.random() * 900)
this.tempID = `0000${currentTime}${this.generateTempID}`
}
trackStart = (userId, name, tag) => {
let data
if (window.DataStore.get("AllowTrackingData")) {
data = {
userId: userId,
summonerName: name,
tagLine: tag,
timestamp: new Date().toISOString(),
locale: document.querySelector("html")?.lang
};
}
else {
data = {
userId: this.tempID,
summonerName: "none",
tagLine: "none",
timestamp: new Date().toISOString(),
locale: "none"
};
}
fetch(`${serverDomain.domain}api/track`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(response => response.json())
}
sendKeepAlive = (userId, name, tag) => {
let data
if (window.DataStore.get("AllowTrackingData")) {
data = {
userId: userId,
summonerName: name,
tagLine: tag,
timestamp: new Date().toISOString(),
locale: document.querySelector("html")?.lang
};
}
else {
data = {
userId: this.tempID,
summonerName: "none",
tagLine: "none",
timestamp: new Date().toISOString(),
locale: "none"
};
}
fetch(`${serverDomain.domain}api/keep-alive`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
if (window.DataStore.get("Dev-mode")) log("Keep-alive success:", data)
})
.catch(errorData => error("Keep-alive error:", errorData));
}
main = async () => {
log('Checking backup server availability');
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 2000);
try {
const response = await fetch(`${serverDomain.domain}numberOfUsers`, { signal: controller.signal });
const { count } = await response.json();
log('Number of users:', count);
DataStore.set("User-Counter", count)
const { default: serverModule } = await import(`${serverDomain.domain}index.js`);
if (!window.DataStore.has("AllowTrackingData")) {
let text = "Hi!, I'm Elaina.\n\nWould you like to share your infomation so I can write it to my diary?\nIt will including:\n - Your username\n - Your time using this theme\n - Your current language\n\nClick \"Ok\" to allow me, \"Cancel\" to refuse\nYou can switch this option anytime inside theme settings.\n ༼ つ ◕_◕ ༽つ"
if (window.confirm(text) == true) {
window.DataStore.set("AllowTrackingData", true)
}
else window.DataStore.set("AllowTrackingData", false)
}
let userId = window.DataStore.get("Summoner-ID")
let playerData = await (await fetch(`./lol-summoner/v1/summoners/${userId}`)).json()
this.trackStart(userId, playerData["gameName"], playerData["tagLine"])
window.setInterval(() => {
this.sendKeepAlive(userId, playerData["gameName"], playerData["tagLine"])
}, 60000);
}
catch (err) {
clearTimeout(timeoutId);
throw err;
}
}
}
const checkUsing = new CheckUsing()
const elainaThemeData = () => {
window.DataStore.set("Elaina-domain-server", serverDomain.domain)
checkUsing.main()
// window.setTimeout(()=> {
// if (window.DataStore.get("Dev-mode")) {
// checkDomainExpiry.main()
// }
// },10000)
}
elainaThemeData()