-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
73 lines (63 loc) · 2.11 KB
/
main.js
File metadata and controls
73 lines (63 loc) · 2.11 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
// Main entry point for the extension
console.log("Extension initialized");
// Initialize the extension when the DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
// Add event listeners to buttons
document.getElementById('positive').addEventListener('click', () => {
sendFeedbackType("positive");
});
document.getElementById('neutral').addEventListener('click', () => {
sendFeedbackType("neutral");
});
document.getElementById('negative').addEventListener('click', () => {
sendFeedbackType("negative");
});
});
// Function to send feedback type
function sendFeedbackType(type) {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
func: fillFeedback,
args: [type]
});
});
}
// Function to fill feedback
async function fillFeedback(type) {
console.log("Starting feedback process for type:", type);
try {
const subjects = await IITJFeedback.API.fetchSubjects();
const pendingSubmissions = [];
// First loop: Collect all subjects and their types
for (const subject of subjects) {
const subjectType = IITJFeedback.Subjects.determineSubjectType(subject);
if (subjectType) {
pendingSubmissions.push({
subject: subject,
subjectType: subjectType
});
}
}
console.log("Collected submissions:", pendingSubmissions);
const results = [];
// Second loop: Submit feedback for all collected subjects
for (const submission of pendingSubmissions) {
if ( submission.subject.course_code !== "LAL4060" ) continue
const feedbackResult = await IITJFeedback.API.submitFeedback(
submission.subject,
submission.subjectType,
type
);
results.push({
subject: submission.subject,
subjectType: submission.subjectType,
feedbackResult: feedbackResult
});
}
console.log("Feedback process completed:", results);
return results;
} catch (error) {
console.error('There was a problem with the feedback operation:', error);
}
}