From ff6a116b398edaede02fd1e7c6bb9eb5dfc35a24 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Thu, 1 Feb 2024 01:45:59 -0800
Subject: feat(reader): add reader beta

---
 src/routes/reader/+page.svelte | 48 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 src/routes/reader/+page.svelte

(limited to 'src/routes/reader/+page.svelte')

diff --git a/src/routes/reader/+page.svelte b/src/routes/reader/+page.svelte
new file mode 100644
index 00000000..96c41754
--- /dev/null
+++ b/src/routes/reader/+page.svelte
@@ -0,0 +1,48 @@
+<script>
+	import InputTemplate from '$lib/Tools/InputTemplate.svelte';
+
+	let submission = '';
+
+	$: mangaDexID = submission.match(/(?<=\/title\/)(.*?)(?=\/)/g);
+</script>
+
+<InputTemplate field="MangaDex URL" bind:submission submitText="Read">
+	{#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="true-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="true-opaque">(⌣_⌣”)</p>
+					{/if}
+				{:catch error}
+					{error}
+				{/await}
+			{:else}
+				Invalid URL
+			{/if}
+		{:catch error}
+			{error}
+		{/await}
+	{:else}
+		Invalid URL
+	{/if}
+</InputTemplate>
-- 
cgit v1.2.3

