-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-script.js
More file actions
83 lines (67 loc) · 1.98 KB
/
content-script.js
File metadata and controls
83 lines (67 loc) · 1.98 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
function notifyStart() {
chrome.runtime.sendMessage({
type: "start-notification", options: {
type: "basic",
iconUrl: "icons/icon128.png",
title: "Timer Started",
message: "Test"
}
});
}
function sendKeyDownMessage() {
chrome.runtime.sendMessage({
type: "keydown",
});
}
function sendSubmitMessage(){
chrome.runtime.sendMessage({
type: "submit",
});
}
function sendSubmissionResultMessage(result){
chrome.runtime.sendMessage({
type: "submissionResult",
options: {result}
});
}
function getButton() {
const startButton = document.createElement("button")
startButton.innerHTML = "Start Solving"
startButton.id = "start-button"
startButton.onclick = () => {
startButton.remove()
notifyStart()
}
return startButton
}
function infiniteScroll() {
setTimeout(() => {
if (document.getElementById("start-button")) {
document.getElementById("start-button").scrollIntoView(true);
infiniteScroll()
}
}, 100)
}
infiniteScroll()
document.getElementById("app").appendChild(getButton())
// Wait for the code input area to arrive,
// and attach a keydown event listener to send a message
// to background.js at every keydown
document.arrive(".react-codemirror2", function() {
this.addEventListener('keydown', (e) => sendKeyDownMessage());
document.unbindArrive(".react-codemirror2");
});
// Wait for the submit button to arrive
// and add its event listener
document.arrive('[data-cy="submit-code-btn"]', function() {
this.addEventListener('click', (e) => {
sendSubmitMessage()
// Wait for arriving result
// Check result of sumbissions
document.arrive('.ant-table-row', function() {
const result = this.children[1].textContent
sendSubmissionResultMessage(result)
document.unbindArrive('.ant-table-row');
});
});
});