-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_script.js
More file actions
47 lines (40 loc) · 1.07 KB
/
content_script.js
File metadata and controls
47 lines (40 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* (c) Devanshu Raj
*/
let styleSheet = `
.copyBtn{
border : 1px solid black;
border-radius : 3px;
background : #e6e6e6;
color : #0f0f0f;
padding : 5px;
display : inline-block;
margin-left : 40px;
font-size : 0.8rem;
font-weight : bold;
}
`;
let style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = styleSheet;
(document.head || document.documentElement).appendChild(style);
window.addEventListener('load', function () {
function copyTest(test) {
let btn = document.createElement('button');
btn.className = 'copyBtn';
btn.innerHTML = 'Copy';
btn.onclick = () => {
window.navigator.clipboard.writeText(test.lastChild.innerText);
};
let head = document.getElementById(test.previousElementSibling.id);
if (!head) {
test.insertBefore(document.createElement('br'), test.childNodes[0]);
test.insertBefore(btn, test.childNodes[0]);
}
if (head) head.appendChild(btn);
}
let tests = document.getElementsByTagName('pre');
for (let test of tests) {
copyTest(test);
}
});