Refactor injection logic with tryInject function

This commit is contained in:
Roy
2026-06-08 03:07:27 -07:00
committed by GitHub
parent 579cdfdef0
commit 4f552c5b3c
+14 -10
View File
@@ -3690,21 +3690,25 @@ SCANNER_CODE = r"""
parent.appendChild(wrapper);
};
let attempts = 0;
const interval = setInterval(() => {
const tryInject = () => {
const target = isGameMode()
? findGameModeTarget()
: findDesktopTarget();
if (target) {
inject(target);
clearInterval(interval);
} else if (++attempts > 20) {
clearInterval(interval);
}
if (target) inject(target);
};
tryInject();
const observer = new MutationObserver(() => {
tryInject();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}, 500);
})();
"""