-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentScript.js
108 lines (84 loc) · 3.07 KB
/
contentScript.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
// Log the current version of the extension
console.log(`running moodle-grader-tweaks ${chrome.runtime.getManifest().version}`);
// Get options from local storage and apply tweaks based on the settings
chrome.storage.local.get({ privateReply: true, highlightRating: true, disableOnBeforeUnload: true }, (options) => {
const { privateReply, highlightRating, disableOnBeforeUnload } = options;
// Apply the tweaks based on the options
if (privateReply) {
// Check and enable the private reply option
checkPrivateReply();
}
if (highlightRating) {
// Highlight the selectbox rating
highlightSelectboxRating();
highlightGradeView();
}
if (disableOnBeforeUnload) {
// Inject the unload.js script into the web page
(function() {
const script = document.createElement('script');
script.src = chrome.runtime.getURL('unload.js');
document.documentElement.appendChild(script);
script.onload = function() {
this.remove();
};
})();
}
});
// Function to check and enable the private reply option
function checkPrivateReply() {
// document.querySelectorAll("input[name='privatereply']").forEach((element) => {
// element.checked = true;
// });
// Observe DOM changes and enable the private reply option when needed
const observer = new MutationObserver(function(mutationsList) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
document.querySelectorAll("input[name='privatereply']").forEach((element) => {
element.checked = true;
});
}
}
});
const config = {
childList: true,
subtree: true
};
observer.observe(document.body, config);
}
function highlightGradeView() {
// Set the background color of "No Apto" grades
document.querySelectorAll('span.gradevalue').forEach(function (element) {
if (element.textContent.trim() === 'No Apto') {
const parentTd = element.closest('td');
if (parentTd) {
parentTd.style.backgroundColor = 'lightpink';
}
}
});
document.querySelectorAll('td.column-grade').forEach(function (element) {
if (element.textContent.trim() === 'No Apto') {
element.style.backgroundColor = 'lightpink';
}
});
}
// Function to highlight the selectbox rating
function highlightSelectboxRating() {
var postToGrade = 0;
document.querySelectorAll("select[name='rating']").forEach(function (select) {
var selectedValue = select.value;
if (selectedValue == '-999') {
select.style.setProperty('border', '2px solid red', 'important');
select.style.setProperty('background-color','lightpink');
// Create a new span element to contain the text
const textElement = document.createElement('span');
// Set the text content of the span element
textElement.textContent = ` ${select[0].label}`;
// Insert the text element after the select box in the DOM
select.insertAdjacentElement('afterend', textElement);
postToGrade += 1;
}
});
if (postToGrade > 0)
console.log(`There are ${postToGrade} post(s) to grade`)
}