Skip to content

Commit ed81a81

Browse files
committed
fix focus bugs (hopefully)
1 parent 2641ae6 commit ed81a81

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/routes/play/+page.svelte

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
trackClick,
1717
} from "$lib/helpers.js";
1818
import { browser } from "$app/environment";
19+
import { ReplicaModificationsStatus } from "@aws-sdk/client-s3";
1920
2021
let game: Game | null = $state(null);
2122
let adblock = $state(false);
@@ -329,6 +330,31 @@
329330
} else {
330331
adContinued = true;
331332
}
333+
334+
if (iframe) {
335+
iframe.focus();
336+
refocus();
337+
} else {
338+
setTimeout(() => {
339+
iframe?.focus();
340+
refocus();
341+
}, 3000); // try to wait 3 seconds before focusing again
342+
}
343+
344+
let tries = 0;
345+
function refocus() {
346+
setTimeout(() => {
347+
if (iframe) {
348+
iframe.blur();
349+
iframe.focus();
350+
} else {
351+
if (++tries < 4) {
352+
// Allow 12 seconds of DOM freeze
353+
refocus();
354+
}
355+
}
356+
}, 3000);
357+
}
332358
}
333359
</script>
334360

@@ -381,7 +407,9 @@
381407
alt={`Cover art for ${game.fName}`}
382408
src="https://cdn.jsdelivr.net/gh/ccported/games@{commitHash}/{game.gameID}{game.thumbPath}"
383409
/>
384-
<div style="color: #aaa;">Build: {commitHash.slice(0, 7)}...{commitHash.slice(-7)}</div>
410+
<div style="color: #aaa;">
411+
Build: {commitHash.slice(0, 7)}...{commitHash.slice(-7)}
412+
</div>
385413
{:else}
386414
<div class="img"></div>
387415
{/if}

0 commit comments

Comments
 (0)