Fixed it so it says copied to clipboard when you click a image/link

Signed-off-by: AvaLilac <amyshimplays@gmail.com>
This commit is contained in:
AvaLilac 2026-02-26 08:41:26 -05:00 committed by GitHub
parent 58088aa094
commit 5c3b0073e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -165,6 +165,18 @@ function toggleFavoritesPanel() {
}, 2000); }, 2000);
} }
function fallbackCopy(text) {
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.style.position = "fixed";
textarea.style.opacity = "0";
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try { document.execCommand("copy"); } catch {}
document.body.removeChild(textarea);
}
function render() { function render() {
grid.innerHTML = ""; grid.innerHTML = "";
@ -274,9 +286,19 @@ function toggleFavoritesPanel() {
card.appendChild(titleOverlay); card.appendChild(titleOverlay);
} }
card.onclick = async () => { card.onclick = () => {
await navigator.clipboard.writeText(item.url); const doToast = () => showToast(card);
showToast(card); if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(item.url)
.then(doToast)
.catch(() => {
fallbackCopy(item.url);
doToast();
});
} else {
fallbackCopy(item.url);
doToast();
}
}; };
grid.appendChild(card); grid.appendChild(card);
@ -324,4 +346,4 @@ new MutationObserver(injectButton)
injectButton(); injectButton();
})(); })();