improve(webui): only send requests for cheats tab when it's opened

This commit is contained in:
Sainan 2024-06-30 07:02:27 +02:00
parent 81cc773faa
commit 3aca930f34

View File

@ -15,7 +15,6 @@ function loginFromLocalStorage() {
window.accountId = data.id; window.accountId = data.id;
window.authz = "accountId=" + data.id + "&nonce=" + data.Nonce; window.authz = "accountId=" + data.id + "&nonce=" + data.Nonce;
updateInventory(); updateInventory();
fetchSettings();
}, },
() => { () => {
logout(); logout();
@ -656,26 +655,6 @@ $("#mod-to-acquire").on("input", () => {
$("#mod-to-acquire").removeClass("is-invalid"); $("#mod-to-acquire").removeClass("is-invalid");
}); });
function fetchSettings() {
fetch("/custom/config")
.then(response => response.json())
.then(json =>
Object.entries(json).forEach(entry => {
const [key, value] = entry;
var x = document.getElementById(`${key}`);
if (x != null) {
if (x.type == "checkbox") {
if (value === true) {
x.setAttribute("checked", "checked");
}
} else if (x.type == "number") {
x.setAttribute("value", `${value}`);
}
}
})
);
}
const uiConfigs = [ const uiConfigs = [
"autoCreateAccount", "autoCreateAccount",
"skipStoryModeChoice", "skipStoryModeChoice",
@ -721,9 +700,29 @@ function doChangeSettings() {
// Cheats route // Cheats route
fetch("http://localhost:61558/ping", { mode: "no-cors" }).then(() => { single.getRoute("/webui/cheats").on("beforeload", function () {
$("#client-cheats-nok").addClass("d-none"); fetch("/custom/config")
.then(response => response.json())
.then(json =>
Object.entries(json).forEach(entry => {
const [key, value] = entry;
var x = document.getElementById(`${key}`);
if (x != null) {
if (x.type == "checkbox") {
if (value === true) {
x.setAttribute("checked", "checked");
}
} else if (x.type == "number") {
x.setAttribute("value", `${value}`);
}
}
})
);
fetch("http://localhost:61558/ping", { mode: "no-cors" })
.then(() => {
$("#client-cheats-ok").removeClass("d-none"); $("#client-cheats-ok").removeClass("d-none");
$("#client-cheats-nok").addClass("d-none");
fetch("http://localhost:61558/skip_mission_start_timer") fetch("http://localhost:61558/skip_mission_start_timer")
.then(res => res.text()) .then(res => res.text())
@ -742,6 +741,11 @@ fetch("http://localhost:61558/ping", { mode: "no-cors" }).then(() => {
document.getElementById("fov_override").oninput = function () { document.getElementById("fov_override").oninput = function () {
fetch("http://localhost:61558/fov_override?" + this.value); fetch("http://localhost:61558/fov_override?" + this.value);
}; };
})
.catch(function () {
$("#client-cheats-nok").removeClass("d-none");
$("#client-cheats-ok").addClass("d-none");
});
}); });
function doUnlockAllFocusSchools() { function doUnlockAllFocusSchools() {