-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontent.js
191 lines (171 loc) · 6.1 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
let logs = [];
let bwc;
let answer;
let logString;
let answerString;
let i;
let SettingsAutoLogin = true;
let SettingsBookworkChecks = true;
let SettingsAutoContinue = true;
let SettingsDarkMode = false;
let usr=null;
let psw=null;
// msgtype = POPUP , PageUpdated, BACKGROUND, SETTING
// todo
// cleanup Logs mord
// rewrite theme thing
// use listeners more.
// rework bookwork checks it kinda works :/
// check that BS AND CS is connected constantly
// START Sparx Maths Student Login
connect();
console.log("Loaded SparxBwk");
autoLogin();
let elementCheckingInterval = setInterval(function(){
test();
}, 400);
// COMMUNICATION
function connect() {
let CsPort = browser.runtime.connect({ name: "port-from-cs" });
CsPort.postMessage({ connection: "CS Connected" });
CsPort.onMessage.addListener((m) => {
if (m.msgType == "PageUpdated") {
CsPort.postMessage({logs: logs, msgType: "POPUP"});
}
else if (m.msgType == "SETTING") {
if (m.usr) {usr=m.usr;}
if (m.psw) {psw=m.psw; autoLogin();}
if (m.id=="checkbox0") {SettingsBookworkChecks=m.checked;}
else if (m.id=="checkbox1") {console.log("rework games?");}
else if (m.id=="checkbox2") {SettingsAutoContinue=m.checked;}
else if (m.id=="checkbox3") {SettingsAutoLogin=m.checked;}
else if (m.id=="checkbox4") {SettingsDarkMode=m.checked;}
}
});
}
// SCRIPT
function autoLogin() {
if (SettingsAutoLogin && document.title.includes("Login") && psw != null) {
console.log("")
usrInput=document.querySelector("#username");
pswInput=document.querySelector("#password");
usrInput.value = usr;
pswInput.value = psw;
loginBtn=document.querySelector(".login-button");
loginBtn.removeAttribute("disabled");
loginBtn.click();
}
}
function test() {
let answerString="";
const submit = document.querySelector("button[class^='_ButtonBase_10evl_1 _FocusTarget_1nxry_1 _ButtonMd_10evl_27 _ButtonBlue_10evl_51 _ButtonContained_10evl_81']");
if(document.querySelector('div[class^="_Chip_oegf6_1 _Selected_oegf6_13 "]') && !submit.classList.contains("_Disabled_10evl_89")&&submit.innerText == "Submit answer"){
let bwc=document.querySelector('div[class^="_Chip_oegf6_1 _Selected_oegf6_13 "]').innerText.replace("Bookwork code: ", "");
if(document.querySelector("input[placeholder='Enter number']")){
const inputs = document.querySelectorAll("input[placeholder='Enter number']");
submit.addEventListener('click', function() {
for (x = 0; x < inputs.length; x++) {
answerString = answerString + " " + inputs[x].value;
}
log(bwc, answerString);
});
}
if(document.querySelector("._OptionSelected_54uav_511")){
const inputs = document.querySelectorAll("._OptionSelected_54uav_511");
submit.addEventListener('click', function() {
for (x = 0; x < inputs.length; x++) {
answerString = answerString + " " + inputs[x].innerText;
}
log(bwc, answerString);
});
}
else if(document.querySelector("._Slot_1468f_635")){
const slots = document.querySelectorAll("._Slot_1468f_635");
submit.addEventListener('click', function() {
for (x = 0; x < slots.length; x++) {
answerString = answerString + " " + slots[x].innerText;
}
log(bwc, answerString);
});
}
else if(document.querySelector("._Tile_1468f_725")){
const cards = document.querySelectorAll("._Tile_1468f_725");
submit.addEventListener('click', function() {
for (x = 0; x < cards.length; x++) {
answerString = answerString + " " + cards[x].innerText;
}
log(bwc, answerString);
});
}
else if (document.getElementsByClassName('katex-mathml') != null) {
tiles = document.getElementsByClassName('katex-mathml');
submit.addEventListener('click', function() {
for (x = 0; x < tiles.length; x++) {
answerString = answerString + " " + tiles[x].innerText;
}
log(bwc, answerString);
});
}
}
}
function log(bwc, answer) {
if (answer == "") {
return;
}
const submit = document.querySelector("button[class^='_ButtonBase_10evl_1 _FocusTarget_1nxry_1 _ButtonMd_10evl_27 _ButtonBlue_10evl_51 _ButtonContained_10evl_81']");
const logString = "[BWC] "+bwc+" [ANSWER] "+answer;
if (logString!=logs[logs.length-1] && logString!=logs[logs.length-2] && logString!=logs[logs.length-3]) {
console.log(logString);
logs.push(logString);
}
}
/*
function logAnswer() {
if(document.querySelector('div[class^="_Chip_1l3e3_1 _Selected_1l3e3_13"]')){
let bwc=document.querySelector('div[class^="_Chip_1l3e3_1 _Selected_1l3e3_13"]').innerText.replace("Bookwork code: ", "");
// bookwork check
if (SettingsBookworkChecks&&document.querySelector("div[class='_WACContent_1cxo7_12']")) {
console.log("[BOOKWORK CHECK] " + bwc);
bwc=bwc.replace("Bookwork ", "");
const wacOptions=document.getElementsByClassName("answer-part");
for (x = 0; x < logs.length; x++) {
if (logs[x].includes(bwc)) {
for (i = 0; i < wacOptions.length; i++) {
if (logs[x].replace("[BWC] "+bwc+" [ANSWER] ", "").includes(wacOptions[i].innerText)) {
console.log(wacOptions[i].innerText);
}
}
}
}
}
// inputs
if(document.querySelector("input[placeholder='Enter number']")){
const inputs = document.querySelectorAll("input[placeholder='Enter number']");
for (i = 0; i < inputs.length; i++) {
log(bwc, inputs[i].value);
}
}
// sections
if(document.getElementsByClassName("_OptionSelected_1yby8_511")) {
const selected = document.getElementsByClassName("_OptionSelected_1yby8_511");
for (i = 0; i < selected.length; i++) {
log(bwc, selected[i].innerText.replace(/\n/g, ''));
}
}
// tiles
if(document.getElementsByClassName("_CardSlot_1yby8_645")) {
const tiles = document.getElementsByClassName("_CardSlot_1yby8_645");
for (i = 0; i < tiles.length; i++) {
log(bwc, tiles[i].innerText.replace(/\n/g, ''));
}
}
// auto continue
if(SettingsAutoContinue&&document.querySelector("div[class^='_Content_10evl_162']")) {
const btn=document.querySelectorAll("div[class^='_Content_10evl_162']");
for (i = 0; i < btn.length; i++) {
if (btn[i].innerText == "Continue"||btn[i].innerText == "Second chance"||btn[i].innerText == "Later") {btn[i].click();}
}
}
}
}
*/