-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentscript.js
More file actions
88 lines (63 loc) · 2.43 KB
/
contentscript.js
File metadata and controls
88 lines (63 loc) · 2.43 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const copyToClipboardAsync = str => {
if (navigator && navigator.clipboard && navigator.clipboard.writeText)
return navigator.clipboard.writeText(str);
return Promise.reject('The Clipboard API is not available.');
}
const copyNodeStyle = (sourceNode, targetNode) => {
const computedStyle = window.getComputedStyle(sourceNode);
for (const key of computedStyle) {
targetNode.style.setProperty(key, computedStyle.getPropertyValue(key), computedStyle.getPropertyPriority(key))
}
}
loading = setInterval(function () {
const header = document.getElementsByClassName('ide-header');
if (!header || header.length == 0) {
console.log('Header not loaded!');
return;
}
const title = document.getElementsByClassName("cg-ide-title");
if (!title || title.length == 0) {
console.log('Game title not loaded!');
return;
}
let button = document.createElement("Button");
let text = document.createTextNode("Copy stderr");
copyNodeStyle(title[0], button);
const rank = document.getElementsByClassName("rank-wrapper");
if (rank && rank.length > 0) {
// console.log("Rank not loaded!");
// Copy color from current League
// TODO: Sometimes rank could not be loaded
const rankStyle = window.getComputedStyle(rank[0]);
button.style.webkitTextFillColor = rankStyle.webkitTextFillColor;
}
button.onclick = function (event) {
console.log("Button clicked!");
let elements = document.getElementsByClassName('stderr');
if (elements.length == 0) {
return;
}
let content = "";
let lines = 0;
for (let turn = 0; turn < elements.length; turn++) {
let element = elements[turn];
/*
element.innerText sometimes have new lines symbols
and sometimes doesn't :/
*/
// content += elements[turn].innerText + "\n";
for (let line of element.getElementsByClassName("outputLine")) {
content += line.innerText + "\n";
lines += 1;
}
}
if (content.length > 0) {
copyToClipboardAsync(content);
alert(`Copied ${lines} lines.`);
}
}
button.appendChild(text);
header[0].appendChild(button);
console.log('Button is added!');
clearInterval(loading);
}, 100); // Checks every 100ms(0.1s)