-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.txt
199 lines (177 loc) · 6.04 KB
/
Log.txt
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// const login = async (user) => {
// await window.api.login().then((loginCreds) => {loginCredentials = loginCreds})
// localStorage.setItem("credentials", loginCredentials);
// localStorage.setItem("auth"+user, loginCredentials);
// await refresh();
// }
// const selectLogin = async (num) => {
// loginCredentials = ( !nullValues.includes(localStorage.getItem(`auth${num}`)) ) ? localStorage.getItem(`auth${num}`) : `{"type": "NoLogin"}`;
// localStorage.setItem("credentials", loginCredentials);
// //@NOTE Should be handled in refresh: selectedProfile = num;
// await refresh(num);
// }
// const logout = async (num) => {
// localStorage.removeItem("auth"+num);
// localStorage.removeItem("credentials");
// await refresh();
// }
// Mini Functions :) Cutie Pies
const lGet = (id, parse) => {
if (parse == "-P") return JSON.parse(localStorage.getItem(id))
return localStorage.getItem(id);
}
const lSet = (id, content) => {
localStorage.setItem(id, content);
}
const lRem = (id) => {
localStorage.removeItem(id);
}
const lNull = (id) => {
let content = lGet(id);
let undefinedValues = [undefined, null, "Cancelled", "", "undefined", `{type: "Undefined"}`];
return undefinedValues.includes(content);
}
const lHas = (id) => {
let content = lGet(id);
let undefinedValues = [undefined, null, "Cancelled", "", "undefined", `{type: "Undefined"}`];
return !undefinedValues.includes(content);
}
const fetchPlayerData = async () => {
let localUUID, response, hasCredentials, runSelection = true, credentials, authList = [];
for (let index = 1; index < profilesAmount + 1; index++) {
if (lNull(`auth${index}`)) {
lSet(`auth${index}`, `{type: "Undefined"}`);
}
}
if (lHas("credentials") && lGet("credentials","-P").type !== "Cancelled") {
hasCredentials = true;
credentials = lGet("credentials");
} else {
hasCredentials = false;
}
if (selected !== 0) {
if (selected == undefined) {
selected = 0;
}
if (lGet(`auth${selected}`) == lGet("credentials")) {
runSelection = false;
} else {
selected = 0;
}
console.log("Selected:", selected);
}
let index = 1;
for (let authName in {...localStorage}) {
let auth = lGet(authName);
if (authName.includes("auth")) {
authList.push({
name: authName,
value: JSON.parse(auth),
});
if (runSelection && hasCredentials) {
if (auth === lGet("credentials")) {
selected = index;
}
}
};
if (auth == `{"type":"Cancelled","translationString":"Cancelled.GUI"}`) {
lSet(authName, undefined);
}
index++;
};
console.log(authList)
if (selected != 0) {
localUUID = JSON.parse(lGet(`auth${selected}`)).profile.id;
await axios.get(`https://playerdb.co/api/player/minecraft/uuid/${localUUID}`)
.then((out) => {
response = out.data.data.player;
});
} else {
return {
credentials: lGet("credentials"),
authList,
};
};
return {
name: response.username,
avatar: response.avatar,
uuid: response.raw_id,
dashedUUID: response.id,
nameHistory: response.meta.name_history,
credentials: JSON.parse(lGet("credentials")),
authList,
};
}
const getProfile = async (name) => {
console.log(selected)
let localUUID, response;
console.log(lGet(`auth${name || selected}`));
localUUID = JSON.parse(lGet(`auth${name || selected}`)).profile.id
axios.get(`https://playerdb.co/api/player/minecraft/uuid/${localUUID}`)
.then((out) => {response = out.data.player;});
return {
name: response.username,
avatar: response.avatar,
uuid: response.raw_id,
dashedUUID: response.id,
nameHistory: response.meta.name_history,
};
}
const dsLog = async (numberID, type) => {
if (type == null) type = "dynamic";
console.log(type)
let authID = `auth${numberID}`;
let altNumberID = numberID == 1 ? 2 : 1;
let altID = `auth${altNumberID}`;
switch(type) {
case "logout":
// Logout if localstorage not null for altID
if (lHas(authID)) lSet(authID, "");
// Set Credentials if another account detected
if (lHas(altID)) lSet("credentials", lGet(altID));
// Otherwise set the credentials to undefined
else lRem("credentials");
selected = altNumberID;
break;
case "login":
// Login if authID empty
if (lNull(authID)) await window.api.login()
.then((loginData) => {
lSet(authID, loginData)
lSet("credentials", loginData)
});
else console.log("Already logged in? An Error Occurred.");
selected = numberID;
break;
case "select":
// Select if authID empty
if (lHas(authID)) {
lSet("credentials", lGet(authID))
selected = numberID;
}
else console.log("No login data detected.");
break;
case "dynamic":
// Login if authID is empty
if (lNull(authID)) {
console.log("Login")
await window.api.login()
.then((loginData) => {
lSet(authID, loginData)
});
}
// Then, if it exists, set its credentials! :)
if (lHas(authID)) {
lSet("credentials", lGet(authID))
selected = numberID;
};
break;
}
}
const refresh = async (num) => {
let playerData = await fetchPlayerData();
skinURL = playerData.avatar;
changes++;
}
const start = async () => {
}