mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 09:28:29 +00:00

Some checks failed
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Waiting to run
Run tests / check lockfile correctness (push) Waiting to run
Run tests / web sanity check (push) Waiting to run
Run tests / api sanity check (push) Waiting to run
Run service tests / test service functionality (push) Has been cancelled
Run service tests / test service: ${{ matrix.service }} (push) Has been cancelled
65 lines
1.7 KiB
Svelte
65 lines
1.7 KiB
Svelte
<script lang="ts">
|
|
import { onMount } from "svelte";
|
|
|
|
import { cachedInfo } from "$lib/api/server-info";
|
|
import { turnstileSolved, turnstileCreated } from "$lib/state/turnstile";
|
|
|
|
import turnstile from "$lib/api/turnstile";
|
|
|
|
let turnstileElement: HTMLElement;
|
|
let turnstileScript: HTMLElement;
|
|
|
|
onMount(() => {
|
|
const sitekey = $cachedInfo?.info?.cobalt?.turnstileSitekey;
|
|
if (!sitekey) return;
|
|
|
|
$turnstileCreated = true;
|
|
|
|
const setup = () => {
|
|
window.turnstile?.render(turnstileElement, {
|
|
sitekey,
|
|
"refresh-expired": "never",
|
|
"retry-interval": 800,
|
|
|
|
"error-callback": (error) => {
|
|
console.log("error code from turnstile:", error);
|
|
return true;
|
|
},
|
|
"expired-callback": () => {
|
|
console.log("turnstile expired, refreshing neow");
|
|
turnstile.reset();
|
|
},
|
|
callback: () => {
|
|
$turnstileSolved = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
if (window.turnstile) {
|
|
setup();
|
|
} else {
|
|
turnstileScript.addEventListener("load", setup);
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<svelte:head>
|
|
<script
|
|
bind:this={turnstileScript}
|
|
src="https://challenges.cloudflare.com/turnstile/v0/api.js"
|
|
defer
|
|
></script>
|
|
</svelte:head>
|
|
|
|
<div id="turnstile-container">
|
|
<div bind:this={turnstileElement} id="turnstile-widget"></div>
|
|
</div>
|
|
|
|
<style>
|
|
#turnstile-container {
|
|
position: absolute;
|
|
z-index: 999;
|
|
right: 0;
|
|
}
|
|
</style>
|