feat: match localhost and fix bool

This commit is contained in:
liooil 2024-12-08 12:24:27 +08:00
parent 9b3d53c1da
commit 4534193cf5

View File

@ -7,6 +7,7 @@
// @author liooil
// @homepage https://xiteng.site/git/liooil/evolve-helper
// @match https://pmotschmann.github.io/Evolve/
// @match http://localhost/Evolve/dist/
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.io
// @updateURL https://xiteng.site/git/liooil/evolve-helper/raw/branch/main/evolve-helper.js
// @downloadURL https://xiteng.site/git/liooil/evolve-helper/raw/branch/main/evolve-helper.js
@ -61,7 +62,7 @@ function auto() {
if (getBool("autoAll")) {
for (const node of document.querySelectorAll("div.action.vb")) {
if (node.classList.contains("cna")) continue;
const a = el.querySelector("a.button");
const a = node.querySelector("a.button");
if (a) a.click();
}
}
@ -152,18 +153,22 @@ function setBool(key, val) {
*/
function menuBtn(nextElementSibling, id, type, defaultVal, cb) {
if (document.getElementById(id)) return;
const getVal = () => {
if (type === "bool") return getBool(id) ?? defaultVal;
else return getInt(id) ?? defaultVal;
};
const el = document.createElement("span");
el.id = id;
el.classList.add("version");
el.style.cursor = "pointer";
el.textContent = `${id}=${getInt(id) ?? defaultVal}`;
el.textContent = `${id}=${getVal()}`;
el.onclick = () => {
let val;
if (type === "bool") {
val = !(getBool(id) ?? defaultVal);
val = !(getVal());
setBool(id, val);
} else {
let input = prompt(`${id}=`, `${getInt(id) ?? defaultVal}`);
let input = prompt(`${id}=`, `${getVal()}`);
if (input === null) return;
val = parseInt(input)
setInt(id, input);