forked from WojtekTB/Chesscom-to-lichess-games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
42 lines (37 loc) · 1.21 KB
/
content.js
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
document.onkeydown = (e) => {
if (e.key == "p") {
//run annalysis
console.log("run annalysis");
document.getElementsByClassName("icon-font-chess share daily-game-footer-icon")[0].click();
setTimeout(() => {
document.getElementsByClassName("board-tab-item-underlined-component share-menu-tab-selector-tab")[0].click();
setTimeout(() => {
let gamePGN = document.getElementsByClassName("form-textarea-component share-menu-tab-pgn-textarea")[0].value;
copyToClipboard(gamePGN);
}, 100);
}, 100);
}
if (e.key == "o") {
let newURL = "https://lichess.org/analysis";
let win = window.open(newURL, "_blank")
win.focus();
}
};
const copyToClipboard = str => {
const el = document.createElement('textarea');
el.value = str;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
};
function rotateBoard() {
attemptToClickKey("board-controls-flip");
}
function fullScreen() {
attemptToClickKey("board-controls-focus");
}
function attemptToClickKey(keyId) {
let key = document.getElementById(keyId);
key.click();
}