2 Commits
Author SHA1 Message Date
fen 3c5ccfb787 Merge pull request '#243: copy button should copy the link' (#244) from fix-243 into dev
CI / test (push) Successful in 19s
CI / docker (push) Successful in 47s
2026-09-16 20:44:56 +00:00
fen 1f745b6e59 #243: copy button copies the paste link; content copy kept on separate button
CI / test (pull_request) Successful in 26s
CI / docker (pull_request) Skipped
2026-09-16 15:40:39 -05:00
2 changed files with 20 additions and 10 deletions
+15 -6
View File
@@ -16,17 +16,24 @@ function toggleStats() {
pill.classList.toggle('open', open); pill.classList.toggle('open', open);
btn.setAttribute('aria-expanded', open ? 'true' : 'false'); btn.setAttribute('aria-expanded', open ? 'true' : 'false');
} }
function copyContent(btn) { function copyFeedback(btn) {
navigator.clipboard.writeText(document.getElementById('raw-content').value); if (!btn) return;
// in-place success feedback (#53)
if (btn) {
btn.classList.add('ok'); btn.classList.add('ok');
btn.textContent = 'Success!'; btn.textContent = 'Success!';
clearTimeout(btn._okh); clearTimeout(btn._okh);
btn._okh = setTimeout(() => { btn.classList.remove('ok'); btn.textContent = 'copy'; }, 2000); btn._okh = setTimeout(() => { btn.classList.remove('ok'); btn.textContent = 'copy'; }, 2000);
} else {
toast('Link Copied', 'success');
} }
function copyContent(btn) {
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() { function redeem() {
if (!confirm('Hard delete this paste immediately?')) return; if (!confirm('Hard delete this paste immediately?')) return;
@@ -41,6 +48,8 @@ function redeem() {
var PASTE_ID = document.currentScript.getAttribute('data-paste-id'); var PASTE_ID = document.currentScript.getAttribute('data-paste-id');
var copyBtn = document.getElementById('copy-btn'); var copyBtn = document.getElementById('copy-btn');
if (copyBtn) copyBtn.addEventListener('click', function (e) { e.preventDefault(); copyContent(copyBtn); }); 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'); var delBtn = document.getElementById('delete-btn');
// #168: show the compact paste-created pill in the bottom corner, then fade it out // #168: show the compact paste-created pill in the bottom corner, then fade it out
+1
View File
@@ -8,6 +8,7 @@
<div class="spacer"></div> <div class="spacer"></div>
<button type="button" class="iconbtn wrap-toggle" title="Toggle line wrap" aria-pressed="false">wrap</button> <button type="button" class="iconbtn wrap-toggle" title="Toggle line wrap" aria-pressed="false">wrap</button>
<a class="iconbtn" href="/raw/{{.ID}}">raw</a> <a class="iconbtn" href="/raw/{{.ID}}">raw</a>
<a class="iconbtn" href="#" id="copy-link-btn">link</a>
<a class="iconbtn" href="#" id="copy-btn">copy</a> <a class="iconbtn" href="#" id="copy-btn">copy</a>
{{if .DeletionToken}}<a class="iconbtn danger" href="#" id="delete-btn">delete</a>{{end}} {{if .DeletionToken}}<a class="iconbtn danger" href="#" id="delete-btn">delete</a>{{end}}
</div> </div>