diff options
| author | Fuwn <[email protected]> | 2023-12-22 00:23:01 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-12-22 00:23:01 -0800 |
| commit | aa0898f8af1705c59e3c402f996f62ade18c4229 (patch) | |
| tree | 4a049f0b97d4aae2545549fe49ef3a48c61d338e /src | |
| parent | feat(layout): no underline links by default (diff) | |
| download | due.moe-aa0898f8af1705c59e3c402f996f62ade18c4229.tar.xz due.moe-aa0898f8af1705c59e3c402f996f62ade18c4229.zip | |
feat(wrapped): filter keywords
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/Tools/Wrapped.svelte | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/lib/Tools/Wrapped.svelte b/src/lib/Tools/Wrapped.svelte index 4311b77c..d49e023f 100644 --- a/src/lib/Tools/Wrapped.svelte +++ b/src/lib/Tools/Wrapped.svelte @@ -19,6 +19,7 @@ import { env } from '$env/dynamic/public'; import { estimatedDayReading } from '$lib/Media/Manga/time'; import ActivityHistoryGrid from './ActivityHistoryGrid.svelte'; + import SettingHint from '$lib/Settings/SettingHint.svelte'; export let user: AniListAuthorisation; @@ -28,6 +29,8 @@ let minutesWatched = 0; let animeList: Media[] | undefined = undefined; let mangaList: Media[] | undefined = undefined; + let originalAnimeList: Media[] | undefined = undefined; + let originalMangaList: Media[] | undefined = undefined; let transparency = false; let lightTheme = true; let watermark = false; @@ -40,6 +43,8 @@ let mounted = false; let generated = false; let disableActivityHistory = true; + let excludedKeywordsInput = ''; + let excludedKeywords: string[] = []; $: { if (browser && mounted) { @@ -71,6 +76,18 @@ new Promise((resolve) => setTimeout(resolve, 1)).then(updateWidth); } + $: { + excludedKeywords = excludedKeywords; + + if (excludedKeywords.length > 0 && animeList !== undefined && mangaList !== undefined) { + animeList = originalAnimeList; + mangaList = originalMangaList; + animeList = excludeKeywords(animeList as Media[]); + mangaList = excludeKeywords(mangaList as Media[]); + } + + updateWidth(); + } const updateWidth = () => { const wrappedContainer = document.querySelector('#wrapped') as HTMLElement; @@ -279,6 +296,37 @@ env.PUBLIC_ANILIST_REDIRECT_URI?.includes('192.168') && !disable ? url : `/api/proxy?url=${encodeURIComponent(url)}`; + + const submitExcludedKeywords = () => { + if (excludedKeywordsInput.length <= 0 && excludedKeywords.length > 0) { + animeList = originalAnimeList; + mangaList = originalMangaList; + excludedKeywords = []; + } else if (excludedKeywordsInput.length >= 0 && excludedKeywords.length <= 0) { + originalAnimeList = animeList; + originalMangaList = mangaList; + } + + if (excludedKeywordsInput.length > 0) + excludedKeywords = excludedKeywordsInput + .split(',') + .map((k) => k.trim()) + .filter((k) => k.length > 0); + }; + + const excludeKeywords = (media: Media[]) => { + if (excludedKeywords.length <= 0) return media; + + return media.filter((m) => { + for (const keyword of excludedKeywords) { + if (m.title.english?.toLowerCase().includes(keyword.toLowerCase())) return false; + if (m.title.romaji?.toLowerCase().includes(keyword.toLowerCase())) return false; + if (m.title.native?.toLowerCase().includes(keyword.toLowerCase())) return false; + } + + return true; + }); + }; </script> {#if currentUserIdentity.id === -2} @@ -455,7 +503,18 @@ <button on:click={updateWidth}>Find best fit</button> <button on:click={() => (width -= 25)}>-25px</button> <button on:click={() => (width += 25)}>+25px</button> - Width adjustment + Width adjustment<br /> + <input + type="text" + bind:value={excludedKeywordsInput} + on:keypress={(e) => { + e.key === 'Enter' && submitExcludedKeywords(); + }} + /> + Excluded keywords + <a href={`#`} on:click={submitExcludedKeywords}>Submit</a> + <br /> + <SettingHint>Comma separated list (e.g., "My Hero, Kaguya")</SettingHint> </div> </details> |