-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent.js
More file actions
101 lines (84 loc) · 2.84 KB
/
content.js
File metadata and controls
101 lines (84 loc) · 2.84 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
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
/**
* Helper Strings
*/
const FRAME = 'ptifrmtgtframe';
const SEARCH_BTN = 'CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH';
const SAVE_BTN = '#ICSave';
const MODIFY_SEARCH_BTN = 'CLASS_SRCH_WRK2_SSR_PB_MODIFY';
const ITEM_CLASS = 'PSHYPERLINK';
const COURSES_QUERY = '[id^="win0divSSR_CLSRSLT_WRK_GROUPBOX2GP$"]';
const DEGREE_SELECT = 'SSR_CLSRCH_WRK_ACAD_CAREER$2';
/**
* Helper Functions
*/
const helperById = (id) => {
return document.getElementById(FRAME).contentWindow.document.getElementById(id);
};
const helperByClassName = (className) => {
return document.getElementById(FRAME).contentWindow.document.getElementsByClassName(className);
};
const helperByQuerySelector = (query) => {
return document.getElementById(FRAME).contentWindow.document.querySelectorAll(query);
};
/**
* Code
*/
let clickRepeat, checkCourses, modifySearch;
chrome.runtime.onMessage.addListener((request) => {
if (request.message === 'start') {
clickRepeat = setInterval(() => {
helperById(DEGREE_SELECT) && (helperById(DEGREE_SELECT).selectedIndex = 4);
helperById(SEARCH_BTN) && helperById(SEARCH_BTN).click();
helperById(SEARCH_BTN) && helperById(SEARCH_BTN).click();
helperById(SAVE_BTN) && helperById(SAVE_BTN).click();
}, 2500);
checkCourses = setInterval(() => {
let courses = [];
let finalList = [];
if (helperById(MODIFY_SEARCH_BTN) != null) {
chrome.storage.sync.get('selectedCourses', (e) => {
e.selectedCourses?.forEach((course) => {
const temp = course.name.split(' : ')[0].split(' ');
courses.push(temp[0] + ' ' + temp[1]);
});
finalList = [...e.selectedCourses];
const listSize = helperByQuerySelector(COURSES_QUERY).length;
let notifFlag = false;
for (let i = 0; i < listSize; i++) {
courses.forEach((course, index) => {
const courseDiv = helperByQuerySelector(COURSES_QUERY)[i];
if (courseDiv.innerText.search(course) != -1) {
finalList[index].status = true;
finalList[index].sections = [];
const secList =
courseDiv.parentNode.parentNode.parentNode.children[1].getElementsByTagName(
'a'
);
for (let j = 8; j < secList.length; j += 9) {
finalList[index].sections.push(secList[j].text.split('-')[0]);
}
notifFlag = true;
}
});
}
chrome.storage.sync.set({
selectedCourses: finalList
});
courses.forEach((_, index) => {
finalList[index].status = false;
finalList[index].sections = [];
});
if (notifFlag) chrome.extension.sendMessage({ todo: 'showCoursesNotif' });
});
}
}, 5000);
modifySearch = setInterval(() => {
if (helperById(MODIFY_SEARCH_BTN) != null) helperById(MODIFY_SEARCH_BTN).click();
}, 9000);
}
if (request.message === 'stop') {
clearInterval(clickRepeat);
clearInterval(checkCourses);
clearInterval(modifySearch);
}
});