mirror of
https://github.com/moraroy/NonSteamLaunchers-On-Steam-Deck.git
synced 2026-06-13 04:04:59 +03:00
Refactor game mode detection and injection logic
This commit is contained in:
+32
-6
@@ -3554,6 +3554,26 @@ SCANNER_CODE = r"""
|
||||
`;
|
||||
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) => {
|
||||
if (!addGame || addGame.parentElement.querySelector(".my-steam-controls")) return;
|
||||
|
||||
@@ -3575,7 +3595,6 @@ SCANNER_CODE = r"""
|
||||
pointerEvents: "auto"
|
||||
});
|
||||
|
||||
|
||||
let autoScan = window.__scan_state === "ON";
|
||||
if (window.__scan_state === "MANUAL") autoScan = false;
|
||||
|
||||
@@ -3673,11 +3692,18 @@ SCANNER_CODE = r"""
|
||||
|
||||
let attempts = 0;
|
||||
const interval = setInterval(() => {
|
||||
const addGame = [...document.querySelectorAll("div")].find(
|
||||
(el) => el.textContent.trim() === "Add a Game"
|
||||
);
|
||||
if (addGame) { inject(addGame); clearInterval(interval); }
|
||||
else if (++attempts > 20) clearInterval(interval);
|
||||
|
||||
const target = isGameMode()
|
||||
? findGameModeTarget()
|
||||
: findDesktopTarget();
|
||||
|
||||
if (target) {
|
||||
inject(target);
|
||||
clearInterval(interval);
|
||||
} else if (++attempts > 20) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
|
||||
}, 500);
|
||||
})();
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user