Refactor game mode detection and injection logic

This commit is contained in:
Roy
2026-06-08 02:35:13 -07:00
committed by GitHub
parent d9afa910c0
commit 579cdfdef0
+32 -6
View File
@@ -3554,6 +3554,26 @@ SCANNER_CODE = r"""
`; `;
document.head.appendChild(style); document.head.appendChild(style);
const isGameMode = () => !!document.querySelector("#Footer");
const findGameModeTarget = () => {
const footer = document.querySelector("#Footer");
if (!footer) return null;
const groups = [...footer.querySelectorAll("div")];
return groups.find(g => {
const text = (g.innerText || "").trim().toLowerCase();
return g.children.length <= 3 && text === "menu";
});
};
const findDesktopTarget = () => {
return [...document.querySelectorAll("div")].find(
(el) => el.textContent.trim() === "Add a Game"
);
};
const inject = (addGame) => { const inject = (addGame) => {
if (!addGame || addGame.parentElement.querySelector(".my-steam-controls")) return; if (!addGame || addGame.parentElement.querySelector(".my-steam-controls")) return;
@@ -3575,7 +3595,6 @@ SCANNER_CODE = r"""
pointerEvents: "auto" pointerEvents: "auto"
}); });
let autoScan = window.__scan_state === "ON"; let autoScan = window.__scan_state === "ON";
if (window.__scan_state === "MANUAL") autoScan = false; if (window.__scan_state === "MANUAL") autoScan = false;
@@ -3673,11 +3692,18 @@ SCANNER_CODE = r"""
let attempts = 0; let attempts = 0;
const interval = setInterval(() => { const interval = setInterval(() => {
const addGame = [...document.querySelectorAll("div")].find(
(el) => el.textContent.trim() === "Add a Game" const target = isGameMode()
); ? findGameModeTarget()
if (addGame) { inject(addGame); clearInterval(interval); } : findDesktopTarget();
else if (++attempts > 20) clearInterval(interval);
if (target) {
inject(target);
clearInterval(interval);
} else if (++attempts > 20) {
clearInterval(interval);
}
}, 500); }, 500);
})(); })();
""" """