From 02cce913039649690c20e35a6acd35c5bc0971a7 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Fri, 22 Aug 2025 17:42:50 +0100 Subject: [PATCH] Tweaked css and debounced image update Signed-off-by: Marcus Noble --- index.html | 8 ++++++-- script.js | 11 ++++++----- style.css | 10 +++++++--- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index 1d57f41..0a12e07 100644 --- a/index.html +++ b/index.html @@ -136,8 +136,12 @@ -
- Source code available on GitHub, GitLab, Bitbucket & my own Gitea server. +
+
+
+ Source code available on GitHub, GitLab, Bitbucket & my own Gitea server. +
+
diff --git a/script.js b/script.js index 528982d..6601e69 100644 --- a/script.js +++ b/script.js @@ -23,6 +23,7 @@ function setWidth(value) { } (() => { + var timeout; let {bskyPost, config} = bindIt({ config: { corsProxy: "https://corsproxy.io/?url=", @@ -163,19 +164,20 @@ function setWidth(value) { bskyPost.externalLink.domain = record.value.embed.external.uri.replaceAll("https://", "").split("/")[0]; bskyPost.externalLink.image = `${config.corsProxy}https://cdn.bsky.app/img/feed_thumbnail/plain/${did}/${record.value.embed.external.thumb.ref["$link"]}@jpeg`; } - - updateImage(); } function updateImage() { - window.requestAnimationFrame(function() { + if (timeout) { + window.cancelAnimationFrame(timeout); + } + timeout = window.requestAnimationFrame(function() { domtoimage.toPng(document.getElementById('post'), { cacheBust: false }) .then(function (dataUrl) { document.getElementById('result-image').src = dataUrl; }); }); } - [...document.querySelectorAll('img')].forEach(el => el.addEventListener("load", updateImage)); + [...document.querySelectorAll('#post img'), ...document.querySelectorAll('#input-form input')].forEach(el => el.addEventListener("load", updateImage)); document.getElementById('submit').addEventListener('click', loadPost); document.getElementById('post-url').addEventListener('change', loadPost); @@ -188,5 +190,4 @@ function setWidth(value) { link.href = document.getElementById('result-image').src; link.click(); }); - })(); diff --git a/style.css b/style.css index 0ca83e9..bd12890 100644 --- a/style.css +++ b/style.css @@ -1,4 +1,3 @@ - body { min-height: 100vh; display: flex; @@ -257,7 +256,12 @@ body { font-variant: no-contextual; } -#download, #result-image { +#result-image { display: block; - margin: 30px auto; + margin: 20px auto; +} + +#download { + display: block; + margin: 10px auto 30px; }