web: load turnstile only in save tab and only once

turnstile will stay in background after being loaded once (just like before), but now it will not load on pages other than save if they are opened first
This commit is contained in:
wukko 2024-09-05 00:04:41 +06:00
parent f0f5d7be7e
commit 49460bd16d
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2
3 changed files with 19 additions and 12 deletions

View file

@ -2,7 +2,7 @@
import env from "$lib/env";
import { onMount } from "svelte";
import { turnstileLoaded } from "$lib/state/turnstile";
import { turnstileLoaded, turnstileCreated } from "$lib/state/turnstile";
let turnstileElement: HTMLElement;
let turnstileScript: HTMLElement;
@ -10,6 +10,9 @@
onMount(() => {
const sitekey = env.TURNSTILE_KEY;
if (!sitekey) return;
$turnstileCreated = true;
const setup = () => {
window.turnstile?.render(turnstileElement, {
sitekey,

View file

@ -1,3 +1,4 @@
import { writable } from "svelte/store";
export const turnstileLoaded = writable(false);
export const turnstileCreated = writable(false);

View file

@ -1,18 +1,21 @@
<script lang="ts">
import { afterNavigate } from "$app/navigation";
import { updated } from "$app/stores";
import { browser } from "$app/environment";
import env from "$lib/env";
import settings from "$lib/state/settings";
import { device, app } from "$lib/device";
import locale from "$lib/i18n/locale";
import currentTheme, { statusBarColors } from "$lib/state/theme";
import "@fontsource/ibm-plex-mono/400.css";
import "@fontsource/ibm-plex-mono/400-italic.css";
import "@fontsource/ibm-plex-mono/500.css";
import { page } from "$app/stores";
import { updated } from "$app/stores";
import { browser } from "$app/environment";
import { afterNavigate } from "$app/navigation";
import env from "$lib/env";
import settings from "$lib/state/settings";
import locale from "$lib/i18n/locale";
import { device, app } from "$lib/device";
import { turnstileCreated } from "$lib/state/turnstile";
import currentTheme, { statusBarColors } from "$lib/state/theme";
import Sidebar from "$components/sidebar/Sidebar.svelte";
import Turnstile from "$components/misc/Turnstile.svelte";
import NotchSticker from "$components/misc/NotchSticker.svelte";
@ -64,7 +67,7 @@
<DialogHolder />
<Sidebar />
<div id="content">
{#if env.TURNSTILE_KEY}
{#if (env.TURNSTILE_KEY && $page.url.pathname === "/") || $turnstileCreated}
<Turnstile />
{/if}
<slot></slot>