From c320f879615da9573a673560a6e8f48fc83e952b Mon Sep 17 00:00:00 2001 From: neri Date: Mon, 20 Dec 2021 01:05:38 +0100 Subject: [PATCH] make copying more generic and hide when unsupported --- static/copy.js | 28 ++++++++++++---------------- template/text-view.html | 8 ++++---- template/upload.html | 9 ++++----- template/url-view.html | 7 +++++-- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/static/copy.js b/static/copy.js index 889b8ff..4f090ec 100644 --- a/static/copy.js +++ b/static/copy.js @@ -1,17 +1,13 @@ -const button = document.getElementById("copy"); -button.classList.remove("hidden"); -button.onclick = () => { - if (!navigator.clipboard) { - button.innerText = "nicht unterstützt"; - return; +if (navigator.clipboard) { + const buttons = document.querySelectorAll("button[data-copy], a[data-copy]"); + for (const button of buttons) { + button.classList.remove("hidden"); + button.onclick = () => { + const target = document.querySelector(button.getAttribute("data-copy")); + navigator.clipboard.writeText(target.textContent).then( + (_) => (button.innerText = "kopiert!"), + (_) => (button.innerText = "nicht unterstützt") + ); + }; } - const content = document.getElementsByClassName("copy-content")[0]; - navigator.clipboard.writeText(content.textContent).then( - (_) => { - button.innerText = "kopiert!"; - }, - (_) => { - button.innerText = "nicht unterstützt"; - } - ); -}; +} diff --git a/template/text-view.html b/template/text-view.html index b644c65..8baba7f 100644 --- a/template/text-view.html +++ b/template/text-view.html @@ -9,12 +9,12 @@

datatrash

- +
herunterladen - +