From: Fuwn Date: Wed, 16 Mar 2022 07:06:32 +0000 (-0700) Subject: feat: image homepages X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=0a903561bab5ae867f1d71b8c22e3f2042d882c6;p=frontend-next.git feat: image homepages --- diff --git a/src/app.css b/src/app.css index 995e9cd..62d6d2e 100644 --- a/src/app.css +++ b/src/app.css @@ -34,15 +34,15 @@ img { border-radius: 5px; } -#random-image img { +.highlight-image img { height: 20em; transition: 0.25s; } -#random-image img:hover { +.highlight-image img:hover { height: 22.5em; opacity: 0.75; } -#random-image a:hover { +.highlight-image a:hover { border-bottom: none; } diff --git a/src/routes/api.svelte b/src/routes/api.svelte index a6476da..e377783 100644 --- a/src/routes/api.svelte +++ b/src/routes/api.svelte @@ -49,6 +49,6 @@ SPDX-License-Identifier: GPL-3.0-only -->

Fetching API README...

{:else} {@html rst2html(rst)} -

RST to HTML time: {rstTime}ms

+

Double rst_to_html_time = {rstTime}; /* ms */

{/if} diff --git a/src/routes/index.svelte b/src/routes/index.svelte index a1a3a1c..12da39e 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -24,7 +24,7 @@ SPDX-License-Identifier: GPL-3.0-only --> onMount(async () => { fetchTime = performance.now(); - image = (await fetchRandomImage()).image; + image = (await fetchRandomImage()); fetchTime = performance.now() - fetchTime; complete = true; }); @@ -40,15 +40,16 @@ SPDX-License-Identifier: GPL-3.0-only --> {#if !complete}

Fetching a random image...

{:else} -
- + -

Fetch time: {fetchTime}ms

+ +

Double fetch_time = {fetchTime}; /* ms */

{/if}

Contributing

diff --git a/src/routes/language.svelte b/src/routes/language.svelte index bbad67b..84bab70 100644 --- a/src/routes/language.svelte +++ b/src/routes/language.svelte @@ -20,15 +20,53 @@ SPDX-License-Identifier: GPL-3.0-only --> import { fetchImages } from "$lib/api"; import { page } from "$app/stores"; + const errorImages = [ + "https://www.pngarts.com/files/8/Confused-Anime-Transparent-Image.png", + "https://cdn130.picsart.com/246838980018212.png?r1024x1024", + "https://toppng.com/public/uploads/thumbnail/confused-anime-png-anime-question-png-gif-11563638774nccphyut3x.png", + "https://linuxreviews.org/images/8/8d/Blond-anime-girl-with-red-questionmark.png", + "https://external-preview.redd.it/VNfYgsb6Pqn4xlEBpYl11534fIpOfN1XeMe7NrzgmQs.png?width=282&auto=webp&s=3247341e1cb8a6d6f63b7b3d63809e52ca0558fd", + "https://i.ya-webdesign.com/images/confused-anime-png-5.png", + "https://www.pngarts.com/files/8/Confused-Anime-PNG-Picture.png", + "https://64.media.tumblr.com/20fb900f57db568393387211c9c4760c/tumblr_olanyyuuQZ1tbejoso2_400.png", + "https://stickershop.line-scdn.net/stickershop/v1/product/7982958/LINEStorePC/main.png;compress=true", + "https://emoji.gg/assets/emoji/8573_Shikiconfused.png", + "https://i.imgur.com/TOgxESH.jpg", + ]; + let language = $page.url.searchParams.get("language"); - let images, fetchTime; + let images, fetchTime, image, imageSize; let complete = false; + let imageQuery = $page.url.searchParams.get("image"); onMount(async () => { fetchTime = performance.now(); images = await fetchImages(language); fetchTime = performance.now() - fetchTime; complete = true; + + if (imageQuery) { + image = images.filter(i => i.includes(imageQuery)); + + if (!image[0]) { + image = "https://www.pngarts.com/files/8/Confused-Anime-Transparent-Image.png"; + image = errorImages[Math.floor(Math.random() * errorImages.length)]; + } else { + let xhr = new XMLHttpRequest(); + + xhr.open("HEAD", image, true); + xhr.onreadystatechange = () => { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + imageSize = `${xhr.getResponseHeader("Content-Length") / 1024}`; + } else { + imageSize = "Error"; + } + } + } + xhr.send(null); + } + } }); @@ -43,11 +81,49 @@ SPDX-License-Identifier: GPL-3.0-only -->

Fetching images...

{:else if images.length === 0}

Sorry, no images were found for this language.

+ {:else if image} + {#if errorImages.includes(image)} +
+

+ Could not locate that specific image! + Wanna go back to language homepage? +

+ + + Image of a confused anime girl + +
+ {:else if image} +
+

+ Wanna go back to language homepage? +

+ + + Image of an anime girl holding a programming book + + +

+ Attributes attributes = + {
+  direct_link: "url",
+  size: {imageSize}, /* kb */
+  fetch_time: {fetchTime}, /* ms */
+ }; +

+
+ {/if} {:else} -

Fetch time: {fetchTime}ms

+ +

Double fetch_time = {fetchTime}; /* ms */

{/if}
diff --git a/src/routes/languages.svelte b/src/routes/languages.svelte index cb1ef69..cf8a05c 100644 --- a/src/routes/languages.svelte +++ b/src/routes/languages.svelte @@ -55,6 +55,7 @@ SPDX-License-Identifier: GPL-3.0-only --> {/each} -

Fetch time: {fetchTime}ms

+ +

Double fetch_time = {fetchTime}; /* ms */

{/if}