XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

fix(webui): remove unnecessary elements when changing language (#1095)

Fixes #1094 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1095 Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>

519cb260
AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
提交于

代码差异

2 个文件 +25 -16
Modified static/webui/index.html +2 -3
@@ -555,9 +555,7 @@
555 555 <form class="mt-2" onsubmit="doChangeSupportedSyndicate(); return false;">
556 556 <label class="form-label" for="changeSyndicate" data-loc="cheats_changeSupportedSyndicate"></label>
557 557 <div class="input-group">
558 <select class="form-control" id="changeSyndicate">
559 <option value="" data-loc="cheats_none"></option>
560 </select>
558 <input class="form-control" id="changeSyndicate" list="datalist-Syndicates" />
561 559 <button class="btn btn-primary" type="submit" data-loc="cheats_changeButton"></button>
562 560 </div>
563 561 </form>
@@ -593,6 +591,7 @@
593 591 <datalist id="datalist-Sentinels"></datalist>
594 592 <datalist id="datalist-ModularParts"></datalist>
595 593 <datalist id="datalist-MechSuits"></datalist>
594 <datalist id="datalist-Syndicates"></datalist>
596 595 <datalist id="datalist-miscitems"></datalist>
597 596 <datalist id="datalist-mods">
598 597 <option data-key="/Lotus/Upgrades/Mods/Fusers/LegendaryModFuser" value="Legendary Core"></option>
Modified static/webui/script.js +23 -13
@@ -129,7 +129,11 @@ function setActiveLanguage(lang) {
129 129
130 130 window.dictPromise = new Promise(resolve => {
131 131 const webui_lang = ["en", "ru", "fr"].indexOf(lang) == -1 ? "en" : lang;
132 const script = document.createElement("script");
132 let script = document.getElementById("translations");
133 if (script) document.documentElement.removeChild(script);
134
135 script = document.createElement("script");
136 script.id = "translations";
133 137 script.src = "/translations/" + webui_lang + ".js";
134 138 script.onload = function () {
135 139 updateLocElements();
@@ -157,6 +161,15 @@ function fetchItemList() {
157 161 req.done(async data => {
158 162 await dictPromise;
159 163
164 document.querySelectorAll('[id^="datalist-"]').forEach(datalist => {
165 datalist.innerHTML = "";
166 });
167
168 const syndicateNone = document.createElement("option");
169 syndicateNone.setAttribute("data-key", "");
170 syndicateNone.value = loc("cheats_none");
171 document.getElementById("datalist-Syndicates").appendChild(syndicateNone);
172
160 173 window.archonCrystalUpgrades = data.archonCrystalUpgrades;
161 174
162 175 const itemMap = {
@@ -198,15 +211,6 @@ function fetchItemList() {
198 211 });
199 212 } else if (type == "uniqueLevelCaps") {
200 213 uniqueLevelCaps = items;
201 } else if (type == "Syndicates") {
202 items.forEach(item => {
203 if (item.uniqueName.startsWith("RadioLegion")) item.name += " (" + item.uniqueName + ")";
204 const option = document.createElement("option");
205 option.value = item.uniqueName;
206 option.innerHTML = item.name;
207 document.getElementById("changeSyndicate").appendChild(option);
208 itemMap[item.uniqueName] = { ...item, type };
209 });
210 214 } else {
211 215 items.forEach(item => {
212 216 if ("badReason" in item) {
@@ -216,6 +220,9 @@ function fetchItemList() {
216 220 item.name += " " + loc("code_badItem");
217 221 }
218 222 }
223 if (type == "Syndicates" && item.uniqueName.startsWith("RadioLegion")) {
224 item.name += " (" + item.uniqueName + ")";
225 }
219 226 if (item.uniqueName.substr(0, 18) != "/Lotus/Types/Game/" && item.badReason != "notraw") {
220 227 const option = document.createElement("option");
221 228 option.setAttribute("data-key", item.uniqueName);
@@ -564,8 +571,10 @@ function updateInventory() {
564 571 single.loadRoute("/webui/inventory");
565 572 }
566 573 }
567
568 document.getElementById("changeSyndicate").value = data.SupportedSyndicate ?? "";
574 document.getElementById("changeSyndicate").value =
575 [...document.querySelectorAll("#datalist-Syndicates option")].find(
576 option => option.getAttribute("data-key") === (data.SupportedSyndicate ?? "")
577 )?.value ?? loc("cheats_none");
569 578 });
570 579 });
571 580 }
@@ -1138,7 +1147,8 @@ function doImport() {
1138 1147 }
1139 1148
1140 1149 function doChangeSupportedSyndicate() {
1141 const uniqueName = document.getElementById("changeSyndicate").value;
1150 const uniqueName = getKey(document.getElementById("changeSyndicate"));
1151
1142 1152 revalidateAuthz(() => {
1143 1153 $.get("/api/setSupportedSyndicate.php?" + window.authz + "&syndicate=" + uniqueName).done(function () {
1144 1154 updateInventory();