Skip to content

Commit 64f5b49

Browse files
committed
Update index.html
1 parent d1665fe commit 64f5b49

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

docs/index.html

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,34 @@
4646
white-space: pre;
4747
margin-bottom: 1.5rem;
4848
border: 1px solid #444;
49+
position: relative;
4950
}
5051

5152
code {
5253
background: none;
5354
color: inherit;
5455
}
5556

57+
.copy-button {
58+
background-color: #4a5568;
59+
color: #fff;
60+
border: none;
61+
border-radius: 4px;
62+
padding: 0.3rem 0.6rem;
63+
font-size: 12px;
64+
font-family: inherit;
65+
cursor: pointer;
66+
transition: background-color 0.2s ease;
67+
position: absolute;
68+
top: 10px;
69+
right: 10px;
70+
z-index: 1;
71+
}
72+
73+
.copy-button:hover {
74+
background-color: #2d3748;
75+
}
76+
5677
table {
5778
width: 100%;
5879
border-collapse: collapse;
@@ -144,13 +165,35 @@ <h1>ValueMapper</h1>
144165
async function loadReadme() {
145166
const res = await fetch('https://raw.githubusercontent.com/TechFusionMasters/ValueMapper/main/README.md');
146167
const markdown = await res.text();
147-
148168
const html = marked.parse(markdown);
149169
document.getElementById('readme-content').innerHTML = html;
170+
addCopyButtons();
171+
}
172+
173+
function addCopyButtons() {
174+
const blocks = document.querySelectorAll("pre > code");
175+
blocks.forEach((codeBlock) => {
176+
const button = document.createElement("button");
177+
button.innerText = "Copy";
178+
button.className = "copy-button";
179+
button.addEventListener("click", async () => {
180+
try {
181+
await navigator.clipboard.writeText(codeBlock.innerText);
182+
button.innerText = "Copied!";
183+
setTimeout(() => (button.innerText = "Copy"), 1500);
184+
} catch (err) {
185+
console.error("Copy failed", err);
186+
button.innerText = "Error";
187+
}
188+
});
189+
190+
const pre = codeBlock.parentNode;
191+
pre.appendChild(button);
192+
});
150193
}
151194

152195
const script = document.createElement('script');
153-
script.src = 'https://cdn.jsdelivr.net/npm/marked/marked.min.js?v=1.0.3'; // cache-busting query
196+
script.src = 'https://cdn.jsdelivr.net/npm/marked/marked.min.js?v=1.0.3';
154197
script.onload = loadReadme;
155198
document.body.appendChild(script);
156199
</script>

0 commit comments

Comments
 (0)