From db17b25a759bde3ebca2b282d1bc45cd51a78840 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Tue, 2 Jan 2024 15:21:59 -0800
Subject: feat(tools): random follower finder

---
 src/lib/Tools/RandomFollower.svelte | 56 +++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 src/lib/Tools/RandomFollower.svelte

(limited to 'src/lib/Tools/RandomFollower.svelte')

diff --git a/src/lib/Tools/RandomFollower.svelte b/src/lib/Tools/RandomFollower.svelte
new file mode 100644
index 00000000..e52d4e86
--- /dev/null
+++ b/src/lib/Tools/RandomFollower.svelte
@@ -0,0 +1,56 @@
+<script lang="ts">
+	import { followers } from '$lib/AniList/following';
+	import RateLimited from '$lib/Error/RateLimited.svelte';
+	import { clearAllParameters } from '$lib/Utility/parameters';
+	import { onMount } from 'svelte';
+
+	let input = '';
+	let submit = '';
+	let randomSeed = 0;
+
+	onMount(clearAllParameters);
+</script>
+
+<p>
+	<!-- svelte-ignore missing-declaration -->
+	<input
+		type="text"
+		placeholder="Username"
+		bind:value={input}
+		on:keypress={(e) => {
+			if (e.key === 'Enter') {
+				submit = input;
+				randomSeed = Math.random();
+
+				// eslint-disable-next-line no-undef
+				umami.track('Random Follower');
+			}
+		}}
+	/>
+	<a
+		href={`#`}
+		on:click={() => (submit = input) && (randomSeed = Math.random())}
+		title="Or click your Enter key"
+		data-umami-event="Random Follower"
+	>
+		Generate
+	</a>
+</p>
+
+{#if submit !== ''}
+	{#await followers(submit)}
+		Loading followers ... 50%
+	{:then users}
+		{@const user = users[Math.floor(randomSeed * users.length)]}
+
+		<p>
+			<a href={`https://anilist.co/user/${user.id}`} target="_blank">
+				{user.name}
+			</a>
+		</p>
+	{:catch}
+		<RateLimited type="Followers" list={false} />
+	{/await}
+{:else}
+	<p>Enter a username to search for to continue.</p>
+{/if}
-- 
cgit v1.2.3

