返回提交历史
Modified
static/webui/script.js
+102
-98
XFEstudio/XFESpaceNinjaServer
chore(webui): add awaitAuthz helper function (#3807)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3807 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
aa1a61ec
代码差异
1 个文件
+102
-98
@@ -186,6 +186,18 @@ function doLogin() {
186
186
window.registerSubmit = false;
187
187
}
188
188
189
function awaitAuthz() {
190
return new Promise(resolve => {
191
let interval;
192
interval = setInterval(() => {
193
if (window.authz) {
194
clearInterval(interval);
195
resolve();
196
}
197
}, 10);
198
});
199
}
200
189
201
function revalidateAuthz() {
190
202
return new Promise(resolve => {
191
203
let interval;
@@ -4055,51 +4067,47 @@ function doSaveConfigStringArray(id) {
4055
4067
}
4056
4068
4057
4069
single.getRoute("/webui/cheats").on("beforeload", function () {
4058
let interval;
4059
interval = setInterval(() => {
4060
if (window.authz) {
4061
clearInterval(interval);
4062
$.post({
4063
url: "/custom/getConfig?" + window.authz,
4064
contentType: "application/json",
4065
data: JSON.stringify(uiConfigs)
4066
})
4067
.done(json => {
4068
//window.is_admin = true;
4069
$(".admin-hide").addClass("d-none");
4070
$(".admin-show").removeClass("d-none");
4071
Object.entries(json).forEach(entry => {
4072
const [key, value] = entry;
4073
const elm = document.getElementById(key);
4074
if (elm.type == "checkbox") {
4075
elm.checked = value;
4076
} else if (elm.classList.contains("tags-input")) {
4077
elm.value = (value ?? []).join(", ");
4078
elm.oninput();
4079
} else {
4080
elm.value = value ?? elm.getAttribute("data-default");
4081
}
4082
});
4083
})
4084
.fail(res => {
4085
if (res.responseText == "Log-in expired") {
4086
if (ws_is_open && !auth_pending) {
4087
console.warn("Credentials invalidated but the server didn't let us know");
4088
sendAuth();
4089
}
4090
revalidateAuthz().then(() => {
4091
if (single.getCurrentPath() == "/webui/cheats") {
4092
single.loadRoute("/webui/cheats");
4093
}
4094
});
4070
awaitAuthz().then(() => {
4071
$.post({
4072
url: "/custom/getConfig?" + window.authz,
4073
contentType: "application/json",
4074
data: JSON.stringify(uiConfigs)
4075
})
4076
.done(json => {
4077
//window.is_admin = true;
4078
$(".admin-hide").addClass("d-none");
4079
$(".admin-show").removeClass("d-none");
4080
Object.entries(json).forEach(entry => {
4081
const [key, value] = entry;
4082
const elm = document.getElementById(key);
4083
if (elm.type == "checkbox") {
4084
elm.checked = value;
4085
} else if (elm.classList.contains("tags-input")) {
4086
elm.value = (value ?? []).join(", ");
4087
elm.oninput();
4095
4088
} else {
4096
//window.is_admin = false;
4097
$(".admin-hide").removeClass("d-none");
4098
$(".admin-show").addClass("d-none");
4089
elm.value = value ?? elm.getAttribute("data-default");
4099
4090
}
4100
4091
});
4101
}
4102
}, 10);
4092
})
4093
.fail(res => {
4094
if (res.responseText == "Log-in expired") {
4095
if (ws_is_open && !auth_pending) {
4096
console.warn("Credentials invalidated but the server didn't let us know");
4097
sendAuth();
4098
}
4099
revalidateAuthz().then(() => {
4100
if (single.getCurrentPath() == "/webui/cheats") {
4101
single.loadRoute("/webui/cheats");
4102
}
4103
});
4104
} else {
4105
//window.is_admin = false;
4106
$(".admin-hide").removeClass("d-none");
4107
$(".admin-show").addClass("d-none");
4108
}
4109
});
4110
});
4103
4111
});
4104
4112
4105
4113
function doUnlockAllFocusSchools() {
@@ -5511,63 +5519,59 @@ function removeItems(category) {
5511
5519
}
5512
5520
5513
5521
single.getRoute("/webui/admin").on("beforeload", function () {
5514
let interval;
5515
interval = setInterval(() => {
5516
if (window.authz) {
5517
clearInterval(interval);
5518
$.get("/custom/getRegisteredLosers?" + window.authz)
5519
.done(users => {
5520
//window.is_admin = true;
5521
$(".admin-hide").addClass("d-none");
5522
$(".admin-show").removeClass("d-none");
5523
document.getElementById("registered-losers").innerHTML = "";
5524
for (const user of users) {
5525
const tr = document.createElement("tr");
5526
{
5527
const td = document.createElement("td");
5528
td.textContent = user.DisplayName;
5529
tr.appendChild(td);
5530
}
5531
{
5532
const td = document.createElement("td");
5533
td.innerHTML = `<code>${user.id}</code>`;
5534
tr.appendChild(td);
5535
}
5536
{
5537
const td = document.createElement("td");
5538
if (window.accountId != user.id) {
5539
const a = document.createElement("a");
5540
a.textContent = loc("admin_possess");
5541
a.setAttribute("data-loc", "admin_possess");
5542
a.href = "#";
5543
a.onclick = function () {
5544
localStorage.setItem("possessing", user.id);
5545
doAccountSwitch("/webui/inventory");
5546
};
5547
td.appendChild(a);
5548
}
5549
tr.appendChild(td);
5550
}
5551
document.getElementById("registered-losers").appendChild(tr);
5522
awaitAuthz().then(() => {
5523
$.get("/custom/getRegisteredLosers?" + window.authz)
5524
.done(users => {
5525
//window.is_admin = true;
5526
$(".admin-hide").addClass("d-none");
5527
$(".admin-show").removeClass("d-none");
5528
document.getElementById("registered-losers").innerHTML = "";
5529
for (const user of users) {
5530
const tr = document.createElement("tr");
5531
{
5532
const td = document.createElement("td");
5533
td.textContent = user.DisplayName;
5534
tr.appendChild(td);
5552
5535
}
5553
})
5554
.fail(res => {
5555
if (res.responseText == "Log-in expired") {
5556
if (ws_is_open && !auth_pending) {
5557
console.warn("Credentials invalidated but the server didn't let us know");
5558
sendAuth();
5536
{
5537
const td = document.createElement("td");
5538
td.innerHTML = `<code>${user.id}</code>`;
5539
tr.appendChild(td);
5540
}
5541
{
5542
const td = document.createElement("td");
5543
if (window.accountId != user.id) {
5544
const a = document.createElement("a");
5545
a.textContent = loc("admin_possess");
5546
a.setAttribute("data-loc", "admin_possess");
5547
a.href = "#";
5548
a.onclick = function () {
5549
localStorage.setItem("possessing", user.id);
5550
doAccountSwitch("/webui/inventory");
5551
};
5552
td.appendChild(a);
5559
5553
}
5560
revalidateAuthz().then(() => {
5561
if (single.getCurrentPath() == "/webui/admin") {
5562
single.loadRoute("/webui/admin");
5563
}
5564
});
5565
} else {
5566
//window.is_admin = false;
5567
$(".admin-hide").removeClass("d-none");
5568
$(".admin-show").addClass("d-none");
5554
tr.appendChild(td);
5569
5555
}
5570
});
5571
}
5572
}, 10);
5556
document.getElementById("registered-losers").appendChild(tr);
5557
}
5558
})
5559
.fail(res => {
5560
if (res.responseText == "Log-in expired") {
5561
if (ws_is_open && !auth_pending) {
5562
console.warn("Credentials invalidated but the server didn't let us know");
5563
sendAuth();
5564
}
5565
revalidateAuthz().then(() => {
5566
if (single.getCurrentPath() == "/webui/admin") {
5567
single.loadRoute("/webui/admin");
5568
}
5569
});
5570
} else {
5571
//window.is_admin = false;
5572
$(".admin-hide").removeClass("d-none");
5573
$(".admin-show").addClass("d-none");
5574
}
5575
});
5576
});
5573
5577
});