forked from smallbasic/smallbasic.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclipboard.js
More file actions
24 lines (23 loc) · 743 Bytes
/
clipboard.js
File metadata and controls
24 lines (23 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function copyText(code, text) {
return function() {
navigator.clipboard.writeText(text);
var color = code.style.borderColor;
code.style.borderColor = "#a2a9b1";
window.setTimeout(function() {
code.style.borderColor = color;
}, 250);
}
}
window.onload = function() {
for (var code of document.getElementsByTagName("pre")) {
var button = document.createElement('button');
var text = document.createElement("span");
text.innerHTML = "📋";
button.appendChild(text);
button.style.float="right";
button.style.border="0";
button.title = "Copy to clipboard";
button.onclick = copyText(code, code.childNodes[0].innerText);
code.insertBefore(button, code.childNodes[0]);
}
}