mirror of
https://github.com/apophenia-news/apophenia.news.git
synced 2026-10-18 09:57:53 +00:00
Add copy article button with full Markdown source
This commit is contained in:
+16
@@ -7,6 +7,22 @@ Alpine.start();
|
||||
|
||||
const bootIcons = () => createIcons({ icons });
|
||||
|
||||
const copyArticleButton = document.querySelector("[data-copy-article]");
|
||||
if (copyArticleButton) {
|
||||
let resetTimer;
|
||||
copyArticleButton.addEventListener("click", async () => {
|
||||
const label = copyArticleButton.querySelector("span");
|
||||
clearTimeout(resetTimer);
|
||||
try {
|
||||
await navigator.clipboard.writeText(JSON.parse(document.querySelector("#article-markdown").textContent));
|
||||
label.textContent = "Copied!";
|
||||
} catch {
|
||||
label.textContent = "Copy failed";
|
||||
}
|
||||
resetTimer = setTimeout(() => (label.textContent = "Copy article"), 2500);
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", bootIcons);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user