aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Tools/SequelSpy.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Tools/SequelSpy.svelte')
-rw-r--r--src/lib/Tools/SequelSpy.svelte41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/lib/Tools/SequelSpy.svelte b/src/lib/Tools/SequelSpy.svelte
index 5386066c..5ef94c1f 100644
--- a/src/lib/Tools/SequelSpy.svelte
+++ b/src/lib/Tools/SequelSpy.svelte
@@ -3,27 +3,42 @@
import { prequels, type MediaPrequel } from '$lib/AniList/prequels';
import MediaTitle from '$lib/List/MediaTitleDisplay.svelte';
import { onMount } from 'svelte';
- import { clearAllParameters } from './tool';
+ import { clearAllParameters, parseOrDefault } from './tool';
import { airingTime } from '$lib/Media/anime';
import type { Media } from '$lib/AniList/media';
+ import { page } from '$app/stores';
+ import { browser } from '$app/environment';
export let user: AniListAuthorisation;
let currentPrequels: Promise<MediaPrequel[]> = Promise.resolve([]) as Promise<MediaPrequel[]>;
- let year = new Date().getFullYear();
- let season = (() => {
- if (new Date().getMonth() >= 0 && new Date().getMonth() <= 2)
- return 'WINTER' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
- else if (new Date().getMonth() >= 3 && new Date().getMonth() <= 5)
- return 'SPRING' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
- else if (new Date().getMonth() >= 6 && new Date().getMonth() <= 8)
- return 'SUMMER' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
- else if (new Date().getMonth() >= 9 && new Date().getMonth() <= 11)
- return 'FALL' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
- else return 'WINTER' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
- })();
+ const urlParameters = browser ? new URLSearchParams(window.location.search) : null;
+ let year = parseOrDefault(urlParameters, 'year', new Date().getFullYear());
+ let season = parseOrDefault(
+ urlParameters,
+ 'season',
+ (() => {
+ if (new Date().getMonth() >= 0 && new Date().getMonth() <= 2)
+ return 'WINTER' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
+ else if (new Date().getMonth() >= 3 && new Date().getMonth() <= 5)
+ return 'SPRING' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
+ else if (new Date().getMonth() >= 6 && new Date().getMonth() <= 8)
+ return 'SUMMER' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
+ else if (new Date().getMonth() >= 9 && new Date().getMonth() <= 11)
+ return 'FALL' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
+ else return 'WINTER' as 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL';
+ })()
+ );
$: currentPrequels = prequels(user, year, season);
+ $: {
+ if (browser) {
+ $page.url.searchParams.set('year', year.toString());
+ $page.url.searchParams.set('season', season.toString());
+ clearAllParameters(['year', 'season']);
+ history.replaceState(null, '', `?${$page.url.searchParams.toString()}`);
+ }
+ }
onMount(clearAllParameters);