-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
119 lines (99 loc) · 3.03 KB
/
script.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
109
110
111
112
113
114
115
116
117
118
class Course {
constructor(name, times, dates) {
this.name = name;
this.times = times;
this.dates = dates;
}
}
function insertScript1() {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
chrome.scripting.executeScript({
target: {
tabId: tabs[0].id
},
function: getClasses
})
})
window.close();
}
function insertScript2() {
chrome.tabs.query({
active: true,
currentWindow: true
}, tabs => {
chrome.scripting.executeScript({
target: {
tabId: tabs[0].id
},
function: mainFunct
})
})
window.close();
}
document.getElementById('buttonGather').addEventListener('click', insertScript1)
document.getElementById('buttonGenerate').addEventListener('click', insertScript2)
function webScrapeCN() {
document.querySelectorAll('.CrsOpen > table a')[1].textContent;
}
function getClasses() {
var regsht = [];
var numCourses = 0;
for (let i = 2; i < (document.querySelectorAll('#grvFirstChoices > tbody > tr').length + 1); i++) {
regsht.push(document.querySelectorAll('#grvFirstChoices > tbody > tr:nth-child(' + i + ') > td:nth-child(4) > span')[0].textContent.trim());
numCourses++;
localStorage.setItem('' + (i - 2), '' + regsht[i - 2]);
}
localStorage.setItem('numCourses', numCourses);
localStorage.setItem('i', '0');
}
function mainFunct() {
var timesList = [];
var datesList = [];
var numSections = 0;
var courses = [];
function webScrapeTime() {
for (let i = 0; i < (document.querySelectorAll('.MainTableRow').length); i++) {
if (!isNaN(document.querySelectorAll('.MainTableRow tbody tr td:nth-child(2)')[i * 3].textContent)) {
timesList.push(document.querySelectorAll('.MainTableRow tbody tr td:nth-child(4)')[i * 2].textContent);
numSections++;
} else {
break;
}
}
}
function webScrapeDate() {
for (let i = 0; i < (document.querySelectorAll('.MainTableRow').length); i++) {
if (!isNaN(document.querySelectorAll('.MainTableRow tbody tr td:nth-child(2)')[i * 3].textContent)) {
datesList.push(document.querySelectorAll('.MainTableRow tbody tr td:nth-child(3)')[i * 2].textContent);
} else {
break;
}
}
}
var searchBar = document.getElementById("Body_txtSearchKeyword");
let i = localStorage.getItem('i');
searchBar.value = localStorage.getItem('' + i)
//document.querySelector('[name="ctl00$Body$ctl15"]').click();
var name = localStorage.getItem('' + i-1);
timesList.length = 0;
datesList.length = 0;
webScrapeTime();
webScrapeDate();
for (let j = 0; j < timesList.length; j++) {
localStorage.setItem(name + '0' + j, timesList[j] + datesList[j]);
}
localStorage.setItem('i', parseInt(i) + 1 + '');
localStorage.setItem(i + 'numSections', numSections);
courses.push({
"name": localStorage.getItem('' + i-1),
"times": timesList,
"dates": datesList,
"noSections": numSections,
"prtimes": [],
"prdates": []
})
console.log(courses[1]);
}