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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
<script lang="ts">
/* eslint svelte/no-at-html-tags: "off" */
import settings from '$stores/settings';
import type { Media } from '$lib/AniList/media';
import { cleanCache, incrementMediaProgress } from '$lib/Media/Anime/cache';
import { totalEpisodes } from '$lib/Media/Anime/episodes';
import type { AniListAuthorisation } from '$lib/AniList/identity';
import ListTitle from '../ListTitle.svelte';
import MediaTitle from '../MediaTitleDisplay.svelte';
import { outboundLink } from '$lib/Media/links';
import { onDestroy, onMount } from 'svelte';
import type { SubsPlease } from '$lib/Media/Anime/Airing/Subtitled/subsPlease';
import HoverCover from '$lib/Media/Cover/HoverCover.svelte';
import {
onMouseEnter,
onMouseLeave,
onMouseMove,
type HoverCoverResponse
} from '$lib/Media/Cover/hoverCover';
import { mediaTitle } from '../mediaTitle';
import tooltip from '$lib/Tooltip/tooltip';
import AiringTime from '$lib/Media/Anime/Airing/AiringTime.svelte';
import { browser } from '$app/environment';
import identity from '$stores/identity';
export let media: Media[];
export let title: any;
export let animeLists: Promise<Media[]>;
export let user: AniListAuthorisation;
export let endTime: number;
export let lastUpdatedMedia: number;
export let completed = false;
export let previousAnimeList: Media[];
export let pendingUpdate: number | null;
export let subsPlease: SubsPlease | null = null;
export let upcoming = false;
export let notYetReleased = false;
let hoverCoverState: HoverCoverResponse = {};
const keyCacher = setInterval(
() => (media = media),
(() => {
const airingAt = media.find((m) => m.nextAiringEpisode?.airingAt)?.nextAiringEpisode
?.airingAt;
const untilAiring = airingAt
? Math.round((airingAt - Date.now() / 1000) * 100) / 100
: undefined;
if (untilAiring && untilAiring < 3600) return 10000;
return 300000;
})()
);
onMount(() => {
if (browser)
localStorage.setItem(
`last${
notYetReleased ? 'NotYetReleased' : upcoming ? 'Upcoming' : completed ? 'Completed' : ''
}AnimeListLength`,
media.length.toString()
);
});
onDestroy(() => clearInterval(keyCacher));
</script>
<ListTitle time={endTime / 1000} count={media.length} {title} />
{#if media.length === 0}
No anime to display. <button on:click={() => (animeLists = cleanCache(user, $identity))}>
Force refresh
</button>
{/if}
{#if $settings.displayCoverMode}
<div
id="covers"
style={`grid-template-columns: repeat(auto-fill, minmax(${$settings.displayCoverWidth}px, 1fr))`}
>
{#each media as anime}
{@const progress = (anime.mediaListEntry || { progress: 0 }).progress}
{#if upcoming || notYetReleased || progress !== (anime.nextAiringEpisode?.episode || 9999) - 1}
<div class="cover-card">
<a
href={outboundLink(anime, 'anime', $settings.displayOutboundLinksTo)}
target="_blank"
title={anime ? mediaTitle(anime) : undefined}
use:tooltip
>
<img class="cover" src={anime.coverImage.extraLarge} alt="Cover" />
</a>
<div class="cover-title">
{#if !upcoming || notYetReleased}
{pendingUpdate === anime.id ? progress + 1 : progress}{@html totalEpisodes(anime)}
<button
class={`button-square button-action ${pendingUpdate === anime.id ? 'opaque' : ''}`}
style={pendingUpdate === anime.id ? 'pointer-events: none;' : ''}
on:click={() => {
if (pendingUpdate !== anime.id) {
lastUpdatedMedia = anime.id;
pendingUpdate = anime.id;
incrementMediaProgress(anime.id, anime.mediaListEntry?.progress, user, () => {
const mediaListEntry = media.find((m) => m.id === anime.id)?.mediaListEntry;
if (mediaListEntry) mediaListEntry.progress = progress + 1;
previousAnimeList = media;
animeLists = cleanCache(user, $identity);
pendingUpdate = null;
});
}
}}>+</button
>
{#if !completed}
[{anime.nextAiringEpisode?.episode === -1
? '?'
: (anime.nextAiringEpisode?.episode || 1) -
((anime.nextAiringEpisode?.airingAt || 999) <
(anime.nextAiringEpisode?.nativeAiringAt || 0)
? 2
: 1)}]
<br />
<AiringTime originalAnime={anime} {subsPlease} />
{/if}
{:else}
<AiringTime originalAnime={anime} {subsPlease} upcoming={true} />
{/if}
</div>
</div>
{/if}
{/each}
</div>
{:else}
<ul>
{#each media as anime}
{@const progress = (anime.mediaListEntry || { progress: 0 }).progress}
{#if upcoming || notYetReleased || progress !== (anime.nextAiringEpisode?.episode || 9999) - 1}
<li class="entry">
<span class="content">
<a
href={outboundLink(anime, 'anime', $settings.displayOutboundLinksTo)}
target="_blank"
on:mouseenter={() => {
const response = onMouseEnter(anime);
hoverCoverState.hovering = response.hovering;
hoverCoverState.item = response.item;
hoverCoverState.media = response.media;
}}
on:mouseleave={() => {
const response = onMouseLeave();
hoverCoverState.hovering = response.hovering;
hoverCoverState.item = response.item;
hoverCoverState.media = response.media;
}}
on:mousemove={(e) => {
const response = onMouseMove(e, 300);
hoverCoverState.style = response.style;
}}
>
<span
style={lastUpdatedMedia === anime.id && anime.episodes !== progress
? 'color: lightcoral'
: ''}
>
<MediaTitle title={anime.title} />
</span>
</a>
{#if $settings.displaySocialButton}
[<a href={`https://anilist.co/anime/${anime.id}/social`} target="_blank">S</a>]
{/if}
{#if !upcoming || notYetReleased || !$settings.displayCountdownRightAligned}
<span class="opaque">|</span>
{/if}
{#if !upcoming || notYetReleased}
<!-- {anime.mediaListEntry?.progress || 0}{@html totalEpisodes(anime)} -->
{pendingUpdate === anime.id ? progress + 1 : progress}{@html totalEpisodes(anime)}
<button
class={`button-square button-action ${pendingUpdate === anime.id ? 'opaque' : ''}`}
style={pendingUpdate === anime.id ? 'pointer-events: none;' : ''}
on:click={() => {
if (pendingUpdate !== anime.id) {
lastUpdatedMedia = anime.id;
pendingUpdate = anime.id;
incrementMediaProgress(anime.id, anime.mediaListEntry?.progress, user, () => {
const mediaListEntry = media.find((m) => m.id === anime.id)?.mediaListEntry;
if (mediaListEntry) mediaListEntry.progress = progress + 1;
previousAnimeList = media;
animeLists = cleanCache(user, $identity);
pendingUpdate = null;
});
}
}}>+</button
>
{#if !completed}
[{anime.nextAiringEpisode?.episode === -1
? '?'
: (anime.nextAiringEpisode?.episode || 1) -
((anime.nextAiringEpisode?.airingAt || 999) <
(anime.nextAiringEpisode?.nativeAiringAt || 0)
? 2
: 1)}]
<span class:countdown={$settings.displayCountdownRightAligned}>
<AiringTime originalAnime={anime} {subsPlease} />
</span>
{/if}
{:else}
<span class:countdown={$settings.displayCountdownRightAligned}>
<AiringTime originalAnime={anime} {subsPlease} upcoming={true} />
</span>
{/if}
</span>
</li>
{/if}
{/each}
</ul>
{/if}
<HoverCover options={hoverCoverState} width={300} />
<style>
#covers {
display: grid;
justify-content: center;
gap: 1em 0.5em;
margin-top: 0.5rem;
}
.cover {
background-size: cover;
background-position: center;
border-radius: 8px;
}
.cover-title {
text-align: center;
margin: 0.25rem;
}
.cover-card {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.entry::after {
content: '';
display: table;
clear: both;
}
.countdown {
white-space: nowrap;
float: right;
}
</style>
|