aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/+page.svelte
blob: 7320c2aeaf029371096dfc89798c1af5433923f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<script lang="ts">
  import { onMount } from 'svelte';
  import Monaco from './Monaco.svelte';
  let content_script = $state('');
  let default_value = $state(`// Do not put untrusted content here!
// See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Intercept_HTTP_requests and https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest for a tutorial on how to handle things.
// Content saves on every keystroke due to laziness.
// Reload (disable & re-enable) extension or restart browser to apply changes.
`);
  let mounted = $state(false);
  onMount(async () => {
    const s = (await browser.storage.local.get('sc')).sc;
    default_value = s && `${s}`.length ? `${s}` : default_value;
    content_script = default_value ?? '';
    setTimeout(() => {
      mounted = true;
      setTimeout(() => {
        content_script = default_value;
      }, 0);
    }, 0);
  });
  $effect(() => {
    (async (cs: string) => {
      if (mounted) {
        await browser.storage.local.set({ sc: cs });
        if (browser.runtime.lastError) {
          console.warn('Last Error is ', browser.runtime.lastError.message);
          browser.runtime.lastError = undefined;
        }
      }
    })(content_script);
  });
</script>

{#if mounted}
  <Monaco
    defaultValue={default_value}
    bind:value={content_script}
  />
{:else}
  Getting Storage
{/if}