-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
48 lines (37 loc) · 1.49 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
chrome.runtime.onMessage.addListener(message => {
if (message.action === "getFileStatus") {
// TODO: debug
//console.log("File status requested!");
const parent = document.querySelector("div.css-ftq10c");
if (!parent) return sendFileStatus(false); // If no parent found return
let identificator;
for (let i = 0; i < parent.childNodes.length; i++) {
const file = parent.childNodes[i];
if (!file.href) continue;
if (!file.href.match(/(https:\/\/wuolah\.com\/apuntes\/)(?<=\/)(.*?)(?=\/).*/gm)) continue;
try {
identificator = file.href.split("-").at(-1);
console.log(identificator)
if (identificator) break;
} catch (error) {
continue;
}
}
if (!identificator) return sendFileStatus(false);
sendFileStatus(true, identificator);
}
});
function sendFileStatus(status, identificator = undefined) {
chrome.runtime.sendMessage({ action: "changeFileStatus", status: status });
if (status) {
chrome.runtime.sendMessage({
action: "downloadInfo",
fileId: identificator,
tokenCookie: Cookies.get("token"),
machineCookie: Cookies.get("segMachineId"),
referralCookie: Cookies.get("invitationCode")
});
}
// TODO: debug
//console.log("Sending file status", status);
}