From 97c529e54012427d179f0ef1bf9f5687b66d4de6 Mon Sep 17 00:00:00 2001 From: roffy3051 Date: Mon, 21 Oct 2024 00:58:30 +0800 Subject: [PATCH] feat(web): show message on error --- assets/script.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/assets/script.js b/assets/script.js index e939766..dee5d84 100644 --- a/assets/script.js +++ b/assets/script.js @@ -31,11 +31,25 @@ } const query = new URLSearchParams(params).toString(); - img.src = `${__global_data.site}/@${name}?${query}`; - code.textContent = img.src; - code.style.visibility = 'visible'; + const imgSrc = `${__global_data.site}/@${name}?${query}`; + img.src = imgSrc - img.onload = () => img.scrollIntoView({ block: 'start', behavior: 'smooth' }); + img.onload = () => { + img.scrollIntoView({ block: 'start', behavior: 'smooth' }); + + code.textContent = imgSrc; + code.style.visibility = 'visible'; + } + + img.onerror = () => { + fetch(imgSrc) + .then(async (res) => { + if (!res.ok) { + const { message } = await res.json(); + alert(message); + } + }) + }; }, 500)); code.addEventListener('click', (e) => {