aboutsummaryrefslogtreecommitdiff
path: root/src/routes/reader/+page.svelte
blob: d591f0e18c4ba2b595428176727fd2d71e9061ca (plain) (blame)
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
<script>
	import InputTemplate from '$lib/Tools/InputTemplate.svelte';

	let submission = '';

	$: mangaDexID = submission.match(/mangadex\.org\/title\/([a-f0-9-]+)\/?/)?.[1];
</script>

<InputTemplate field="MangaDex URL" bind:submission submitText="Read" preserveCase>
	{#if mangaDexID}
		{#await fetch(`https://api.mangadex.org/manga/${mangaDexID}/feed?order[chapter]=desc&translatedLanguage[]=en`) then response}
			{#if response.ok}
				{#await response.json() then data}
					{#if data.data}
						<ul>
							{#each data.data as chapter}
								<li>
									{#if chapter.attributes.volume}
										Vol. {chapter.attributes.volume}
									{/if}
									Ch. {chapter.attributes.chapter}
									<span class="opaque">|</span>
									<a
										href={`https://mangadex.org/chapter/${chapter.id}`}
										target="_blank"
										rel="noopener noreferrer"
									>
										{chapter.attributes.title}
									</a>
								</li>
							{/each}
						</ul>
					{:else}
						<p class="opaque">(⌣_⌣”)</p>
					{/if}
				{:catch error}
					{error}
				{/await}
			{:else}
				Invalid URL
			{/if}
		{:catch error}
			{error}
		{/await}
	{:else}
		Invalid URL
	{/if}
</InputTemplate>