Skip to content

Commit 4743e76

Browse files
committed
Add Copy button for share URL
1 parent 120b662 commit 4743e76

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎index.css‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,20 @@ html {
9595

9696
#share-url {
9797
flex: 1;
98+
min-width: 0;
9899
padding: 6px 8px;
99100
font-size: 12px;
100101
border: 1px solid #ccc;
101102
border-radius: 3px;
102103
}
103104

105+
#copy-url-btn {
106+
padding: 6px 10px;
107+
font-size: 12px;
108+
cursor: pointer;
109+
white-space: nowrap;
110+
}
111+
104112
.no-functions {
105113
padding: 20px;
106114
color: #856404;

‎index.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<div class="share-block">
2121
<label>Share URL:</label>
2222
<input type="text" id="share-url" readonly />
23+
<button id="copy-url-btn" title="Copy to clipboard">Copy</button>
2324
</div>
2425
<div id="editor"></div>
2526
<div class="button-bar">

‎main.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ function setupResizableGutter() {
210210

211211
window.addEventListener("DOMContentLoaded", () => {
212212
document.getElementById("execute-btn").addEventListener("click", executeCode);
213+
document.getElementById("copy-url-btn").addEventListener("click", () => {
214+
const url = document.getElementById("share-url").value;
215+
navigator.clipboard.writeText(url).then(() => {
216+
const btn = document.getElementById("copy-url-btn");
217+
btn.textContent = "Copied!";
218+
setTimeout(() => { btn.textContent = "Copy"; }, 1500);
219+
});
220+
});
213221
setupResizableGutter();
214222
initWorker();
215223
});

0 commit comments

Comments
 (0)