From bbc58e7fa0605200197acee2e45f71adf0676462 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Tue, 30 Apr 2024 14:58:33 -0700
Subject: feat(BadgePreview): simple source name

---
 src/lib/User/BadgeWall/BadgePreview.svelte | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

(limited to 'src/lib/User/BadgeWall/BadgePreview.svelte')

diff --git a/src/lib/User/BadgeWall/BadgePreview.svelte b/src/lib/User/BadgeWall/BadgePreview.svelte
index ac1d13ec..4c374a27 100644
--- a/src/lib/User/BadgeWall/BadgePreview.svelte
+++ b/src/lib/User/BadgeWall/BadgePreview.svelte
@@ -60,6 +60,24 @@
 			document.removeEventListener('click', handleClickOutside);
 		};
 	});
+
+	// generate a tag for the source
+	const classifySource = (source: string) => {
+		let name = source;
+		const sourceLower = source.toLowerCase();
+
+		if (sourceLower.includes('pixiv.net')) {
+			name = 'Pixiv';
+		} else if (sourceLower.includes('twitter.com') || sourceLower.includes('x.com')) {
+			name = 'X (Twitter)';
+		} else if (sourceLower.includes('zerochan.net')) {
+			name = 'Zerochan';
+		} else if (sourceLower.includes('imgur.com')) {
+			name = 'Imgur';
+		}
+
+		return `<a href="${source}" target="_blank">${name}</a>`;
+	};
 </script>
 
 {#if selectedBadge}
@@ -131,9 +149,10 @@
 			<b>Source:</b>
 
 			{#if selectedBadge.source.startsWith('http')}
-				<a href={selectedBadge.source} target="_blank">
+				<!-- <a href={selectedBadge.source} target="_blank">
 					{selectedBadge.source}
-				</a>
+				</a> -->
+				{@html classifySource(selectedBadge.source)}
 			{:else}
 				{selectedBadge.source}
 			{/if}
-- 
cgit v1.2.3

