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
|
<script lang="ts">
import { ACDBBirthdays, type ACDBBirthday } from '$lib/Birthday/ACDB';
import { aniSearchBirthdays, type aniSearchBirthday } from '$lib/Birthday/aniSearch';
import Error from '$lib/Error.svelte';
import { onMount } from 'svelte';
interface Birthday {
name: string;
image: string;
origin?: string;
}
let date = new Date();
let month = date.getMonth() + 1;
let day = date.getDate();
let anisearchBirthdays: Promise<aniSearchBirthday[]>;
let acdbBirthdays: Promise<ACDBBirthday[]>;
$: {
anisearchBirthdays = aniSearchBirthdays(month, day);
acdbBirthdays = ACDBBirthdays(month, day);
}
function normalizeName(name: string): string {
return name.toLowerCase().split(' ').sort().join(' ');
}
function combineBirthdaySources(
acdb: ACDBBirthday[],
aniSearch: aniSearchBirthday[]
): Birthday[] {
const nameMap = new Map<string, Birthday>();
for (const entry of aniSearch.map((entry) => ({
...entry,
normalized_name: normalizeName(entry.name)
}))) {
nameMap.set(entry.normalized_name, {
name: entry.name,
image: entry.image
});
}
for (const entry of acdb) {
const normalized_name = normalizeName(entry.name);
if (!nameMap.has(normalized_name)) {
nameMap.set(normalized_name, {
name: entry.name,
image: entry.character_image,
origin: entry.origin
});
}
}
return Array.from(nameMap.values());
}
</script>
{#await acdbBirthdays}
<p>Loading set one ...</p>
{:then acdbBirthdays}
{#await anisearchBirthdays}
<p>Loading set two ...</p>
{:then anisearch}
{@const birthdays = combineBirthdaySources(acdbBirthdays, anisearch)}
<p>
<select bind:value={month}>
{#each Array.from({ length: 12 }, (_, i) => i + 1) as month}
<option value={month}>
{new Date(0, month - 1).toLocaleString('default', { month: 'long' })}
</option>
{/each}
</select>
<select bind:value={day}>
{#each Array.from({ length: 31 }, (_, i) => i + 1) as day}
<option value={day}>{day}</option>
{/each}
</select>
</p>
<div id="characters">
{#each birthdays as birthday}
<div>
<a
href={`https://anilist.co/search/characters?search=${encodeURIComponent(
birthday.name
).replace(/%20/g, '+')}`}
target="_blank"
>
{birthday.name}
<img src={birthday.image} alt="Character (Large)" class="character-image" />
</a>
</div>
{/each}
</div>
{:catch}
<Error type="Character" />
{/await}
{:catch}
<Error type="Character" />
{/await}
<style>
#characters {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(8%, 1fr));
grid-gap: 0.25%;
grid-row-gap: 1rem;
}
</style>
|