aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Tools/SequelSpy.svelte
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-12-14 16:43:33 -0800
committerFuwn <[email protected]>2023-12-14 16:43:33 -0800
commit2cca45221b7bd1dc3d65361a341a7310271a280d (patch)
tree3b7b4ca1ce27ab1503de7a23ea7eb1dca31d1cc6 /src/lib/Tools/SequelSpy.svelte
parentfeat(sequelspy): display upcoming date (diff)
downloaddue.moe-2cca45221b7bd1dc3d65361a341a7310271a280d.tar.xz
due.moe-2cca45221b7bd1dc3d65361a341a7310271a280d.zip
feat(sequelspy): save options
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);