-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
43 lines (38 loc) · 1.47 KB
/
Copy pathcontent.js
File metadata and controls
43 lines (38 loc) · 1.47 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
const rows = document.querySelectorAll("tr");
rows.forEach(row => {
if (row.querySelector("td.course_header")) {
return;
}
const uniqueCell = row.querySelector('td[data-th="Unique"] a');
if (!uniqueCell) {
return;
}
const btn = document.createElement("button");
btn.textContent = "+";
btn.className = "watchlist-add-btn";
btn.style.display = "flex";
btn.style.justifyContent = "center";
btn.style.alignItems = "center";
const btnContainer = document.createElement("td");
btnContainer.appendChild(btn);
row.appendChild(btnContainer);
btn.addEventListener("click", () => {
const course = {
unique: uniqueCell.textContent.trim(),
days: row.querySelector('td[data-th="Days"]')?.innerText.trim(),
hours: row.querySelector('td[data-th="Hour"]')?.innerText.trim(),
room: row.querySelector('td[data-th="Room"]')?.innerText.trim(),
instructor: row.querySelector('td[data-th="Instructor"]')?.innerText.trim(),
status: row.querySelector('td[data-th="Status"]')?.innerText.trim(),
url: window.location.href
};
if (btn.textContent === "+") {
chrome.runtime.sendMessage({action: "AddToWatchlist", course: course});
btn.textContent = "-";
}
else {
chrome.runtime.sendMessage({action: "RmvFromWatchlist", course: course});
btn.textContent = "+";
}
})
})