From 1f745b6e59d24a58d943614d879c55b89cb0ce49 Mon Sep 17 00:00:00 2001 From: fen Date: Wed, 16 Sep 2026 15:40:39 -0500 Subject: [PATCH] #243: copy button copies the paste link; content copy kept on separate button --- internal/web/static/paste.js | 29 +++++++++++++++++++---------- internal/web/templates/paste.html | 1 + 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/internal/web/static/paste.js b/internal/web/static/paste.js index ff74ca1..8796837 100644 --- a/internal/web/static/paste.js +++ b/internal/web/static/paste.js @@ -16,17 +16,24 @@ function toggleStats() { pill.classList.toggle('open', open); btn.setAttribute('aria-expanded', open ? 'true' : 'false'); } +function copyFeedback(btn) { + if (!btn) return; + btn.classList.add('ok'); + btn.textContent = 'Success!'; + clearTimeout(btn._okh); + btn._okh = setTimeout(() => { btn.classList.remove('ok'); btn.textContent = 'copy'; }, 2000); +} function copyContent(btn) { - navigator.clipboard.writeText(document.getElementById('raw-content').value); - // in-place success feedback (#53) - if (btn) { - btn.classList.add('ok'); - btn.textContent = 'Success!'; - clearTimeout(btn._okh); - btn._okh = setTimeout(() => { btn.classList.remove('ok'); btn.textContent = 'copy'; }, 2000); - } else { - toast('Link Copied', 'success'); - } + navigator.clipboard.writeText(document.getElementById('raw-content').value) + .then(() => copyFeedback(btn)) + .catch(() => toast('Copy failed')); +} +// #243: copy the paste LINK (full URL), not the paste id or content +function copyLink(btn) { + const url = location.origin + location.pathname; + navigator.clipboard.writeText(url) + .then(() => copyFeedback(btn)) + .catch(() => toast('Copy failed')); } function redeem() { if (!confirm('Hard delete this paste immediately?')) return; @@ -41,6 +48,8 @@ function redeem() { var PASTE_ID = document.currentScript.getAttribute('data-paste-id'); var copyBtn = document.getElementById('copy-btn'); if (copyBtn) copyBtn.addEventListener('click', function (e) { e.preventDefault(); copyContent(copyBtn); }); +var copyLinkBtn = document.getElementById('copy-link-btn'); +if (copyLinkBtn) copyLinkBtn.addEventListener('click', function (e) { e.preventDefault(); copyLink(copyLinkBtn); }); var delBtn = document.getElementById('delete-btn'); // #168: show the compact paste-created pill in the bottom corner, then fade it out diff --git a/internal/web/templates/paste.html b/internal/web/templates/paste.html index a984a06..ba43cb7 100644 --- a/internal/web/templates/paste.html +++ b/internal/web/templates/paste.html @@ -8,6 +8,7 @@
raw + link copy {{if .DeletionToken}}delete{{end}}