Merge pull request #41 from Lukas-Zenick/Similar-Schedule-Fix
This commit is contained in:
@@ -170,37 +170,66 @@ function setDefaultOptions() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// scrape the registrar schedules page for caching the current active semesters
|
async function getCurrentSemesters() {
|
||||||
function getCurrentSemesters() {
|
let webData;
|
||||||
$.get("https://registrar.utexas.edu/schedules", function (response) {
|
if(Object.keys(current_semesters).length > 0) {
|
||||||
if (response) {
|
chrome.storage.local.set({
|
||||||
htmlToNode(response)
|
semesterCache: current_semesters
|
||||||
.find(".callout2>ul>li>a")
|
});
|
||||||
.each(function (i) {
|
}
|
||||||
// only show as many semesters as we want to display
|
async function goFetch(linkend="") {
|
||||||
if (i < Popup.num_semesters) {
|
console.log("lk " + linkend)
|
||||||
let sem_name = $(this).text().trim();
|
return fetch("https://registrar.utexas.edu/schedules/" + linkend)
|
||||||
if (sem_name != "Course Schedule Archive") {
|
.then((response) => {
|
||||||
// $("#semesters").append(`<option>${sem_name}</option>`);
|
return response.text()
|
||||||
current_semesters[sem_name] = "code";
|
.then((data) => {
|
||||||
$.get($(this).attr("href"), function (response) {
|
return data;
|
||||||
if (response) {
|
}).catch((err) => {
|
||||||
let response_node = htmlToNode(response);
|
console.log(err);
|
||||||
let name = response_node.find(".page-title").text().substring(17).trim();
|
})
|
||||||
response_node.find(".gobutton>a").each(function () {
|
});
|
||||||
let link = $(this).attr("href");
|
}
|
||||||
var sem_num = link.substring(link.lastIndexOf("/") + 1).trim();
|
|
||||||
if (current_semesters[name] != sem_num) {
|
await goFetch().then((data) => {webData = data});
|
||||||
current_semesters[name] = sem_num;
|
if(webData == null) {
|
||||||
}
|
webData = ""
|
||||||
});
|
}
|
||||||
}
|
let arr = webData.split("\n");
|
||||||
});
|
let i = 0
|
||||||
}
|
for(let row=0; row<arr.length; row++) {
|
||||||
|
let currentRow = arr[row]
|
||||||
|
if(currentRow.startsWith('<li><a href="https://registrar.utexas.edu/schedules/') && currentRow[52] != "a") {
|
||||||
|
let newWebData;
|
||||||
|
|
||||||
|
// let start = currentRow.indexOf('Schedule">')+10;
|
||||||
|
let start = Math.max(currentRow.lastIndexOf('Summer'), Math.max(currentRow.lastIndexOf('Spring'), currentRow.lastIndexOf('Fall')))
|
||||||
|
let end = currentRow.indexOf('</a></li>');
|
||||||
|
console.log(currentRow)
|
||||||
|
console.log(start + " " + end)
|
||||||
|
let name = currentRow.substring(start,end);
|
||||||
|
console.log("my name: " + name)
|
||||||
|
|
||||||
|
let num = currentRow.indexOf('"https://registrar.utexas.edu/schedules/">')+53;
|
||||||
|
let numend = currentRow.indexOf('" target');
|
||||||
|
let short_sem_num = currentRow.substring(num,numend);
|
||||||
|
current_semesters[name] = "code";
|
||||||
|
|
||||||
|
await goFetch(short_sem_num).then((data) => {newWebData = data});
|
||||||
|
arr2 = newWebData.split("\n")
|
||||||
|
|
||||||
|
for(let row2=0; row2<arr2.length; row2++) {
|
||||||
|
if(arr2[row2].startsWith('<div class="gobutton"><a href="')) {
|
||||||
|
let start2 = arr2[row2].indexOf('<div class="gobutton"><a href="')+31;
|
||||||
|
let end2 = arr2[row2].indexOf('" target="');
|
||||||
|
var scheduleLink = arr2[row2].substring(start2,end2);
|
||||||
|
var sem_num = scheduleLink.substring(scheduleLink.lastIndexOf("/") + 1).trim();
|
||||||
|
if (current_semesters[name] != sem_num) {
|
||||||
|
current_semesters[name] = sem_num;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use the utexas review api for getting the list of departments
|
// use the utexas review api for getting the list of departments
|
||||||
|
|||||||
20
js/import.js
20
js/import.js
@@ -16,7 +16,7 @@ $(function () {
|
|||||||
$("#import").click(function () {
|
$("#import").click(function () {
|
||||||
search_nodes = waitlist ? $(".tbg").last().find(".tbon>td:first-child") : $("tr>td:first-child");
|
search_nodes = waitlist ? $(".tbg").last().find(".tbon>td:first-child") : $("tr>td:first-child");
|
||||||
$(search_nodes).each(function () {
|
$(search_nodes).each(function () {
|
||||||
importCourse($(this));
|
importCourse($(this), true);
|
||||||
})
|
})
|
||||||
importButtonAnimation($(this));
|
importButtonAnimation($(this));
|
||||||
});
|
});
|
||||||
@@ -24,7 +24,7 @@ $(function () {
|
|||||||
$("#import_waitlist").click(function () {
|
$("#import_waitlist").click(function () {
|
||||||
search_nodes = $("tr.tb span:first-child");
|
search_nodes = $("tr.tb span:first-child");
|
||||||
$(search_nodes).each(function () {
|
$(search_nodes).each(function () {
|
||||||
importCourse($(this));
|
importCourse($(this), false);
|
||||||
})
|
})
|
||||||
importButtonAnimation($(this));
|
importButtonAnimation($(this));
|
||||||
});
|
});
|
||||||
@@ -61,17 +61,17 @@ function importButtonAnimation(button) {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function importCourse(unique_node) {
|
function importCourse(unique_node, force) {
|
||||||
let unique = $(unique_node).text().replace(/\s/g, '');
|
let unique = $(unique_node).text().replace(/\s/g, '').substring(0,5);
|
||||||
link = `https://utdirect.utexas.edu/apps/registrar/course_schedule/${sem}/${unique}/`;
|
link = `https://utdirect.utexas.edu/apps/registrar/course_schedule/${sem}/${unique}/`;
|
||||||
buildAddCourse(link);
|
buildAddCourse(link, force)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function buildAddCourse(link) {
|
function buildAddCourse(link, force) {
|
||||||
$.get(link, function (response) {
|
$.get(link, function (response) {
|
||||||
if (response) {
|
if (response) {
|
||||||
let simp_course = buildSimplifiedCourseObject(response, link);
|
let simp_course = buildSimplifiedCourseObject(response, link, force);
|
||||||
chrome.runtime.sendMessage({
|
chrome.runtime.sendMessage({
|
||||||
command: "courseStorage",
|
command: "courseStorage",
|
||||||
course: simp_course,
|
course: simp_course,
|
||||||
@@ -86,7 +86,7 @@ function buildAddCourse(link) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function buildSimplifiedCourseObject(response, link) {
|
function buildSimplifiedCourseObject(response, link, force) {
|
||||||
let imported_course = getCourseObject(htmlToNode(response), link);
|
let imported_course = getCourseObject(htmlToNode(response), link);
|
||||||
let {
|
let {
|
||||||
full_name,
|
full_name,
|
||||||
@@ -97,7 +97,9 @@ function buildSimplifiedCourseObject(response, link) {
|
|||||||
register
|
register
|
||||||
} = curr_course;
|
} = curr_course;
|
||||||
let dtarr = getDayTimeArray(undefined, curr_course);
|
let dtarr = getDayTimeArray(undefined, curr_course);
|
||||||
|
if(force === true) {
|
||||||
|
status = "open" //forces the green status for courses a user is already registered for
|
||||||
|
}
|
||||||
return new Course(full_name, unique, prof_name, dtarr, status, individual, register);
|
return new Course(full_name, unique, prof_name, dtarr, status, individual, register);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
js/util.js
31
js/util.js
@@ -173,20 +173,26 @@ function semesterSort(semA, semB) {
|
|||||||
/* convert from the dtarr and maek the time lines*/
|
/* convert from the dtarr and maek the time lines*/
|
||||||
function convertDateTimeArrToLine(datetimearr) {
|
function convertDateTimeArrToLine(datetimearr) {
|
||||||
var output = [];
|
var output = [];
|
||||||
console.log(datetimearr)
|
|
||||||
var dtmap = makeDateTimeMap(datetimearr);
|
var dtmap = makeDateTimeMap(datetimearr);
|
||||||
var timearr = Array.from(dtmap.keys());
|
var timearr = Array.from(dtmap.keys());
|
||||||
var dayarr = Array.from(dtmap.values());
|
var temporary = Array.from(dtmap.values())
|
||||||
console.log(timearr);
|
var dayarr = []
|
||||||
console.log(dayarr);
|
var locarr = []
|
||||||
|
for(x in temporary) {
|
||||||
|
dayarr.push(temporary[x][0])
|
||||||
|
locarr.push(temporary[x][1])
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0; i < dayarr.length; i++) {
|
for (var i = 0; i < dayarr.length; i++) {
|
||||||
var place = findLocation(dayarr[i], timearr[i], datetimearr);
|
//var place = findLocation(dayarr[i], timearr[i], datetimearr);
|
||||||
|
var place = locarr[i]
|
||||||
var building = place.substring(0, place.search(/\d/)).trim();
|
var building = place.substring(0, place.search(/\d/)).trim();
|
||||||
building = building ? building : "Undecided Location"
|
building = building ? building : "Undecided Location"
|
||||||
|
var timearrsplit = timearr[i].split(',')
|
||||||
output.push({
|
output.push({
|
||||||
"days": dayarr[i],
|
"days": dayarr[i],
|
||||||
"start_time": timearr[i].split(",")[0],
|
"start_time": timearrsplit[0],
|
||||||
"end_time": timearr[i].split(',')[1],
|
"end_time": timearrsplit[1],
|
||||||
"location_link": `https://maps.utexas.edu/buildings/UTM/${building}`,
|
"location_link": `https://maps.utexas.edu/buildings/UTM/${building}`,
|
||||||
"location_full": place
|
"location_full": place
|
||||||
})
|
})
|
||||||
@@ -201,10 +207,15 @@ function makeDateTimeMap(datetimearr) {
|
|||||||
datetimearr[i][1][1] = moment(datetimearr[i][1][1], ["HH:mm A"]).format("h:mm A");
|
datetimearr[i][1][1] = moment(datetimearr[i][1][1], ["HH:mm A"]).format("h:mm A");
|
||||||
}
|
}
|
||||||
for (var i = 0; i < datetimearr.length; i++) {
|
for (var i = 0; i < datetimearr.length; i++) {
|
||||||
if (dtmap.has(String(datetimearr[i][1]))) {
|
var instance = datetimearr[i]
|
||||||
dtmap.set(String(datetimearr[i][1]), dtmap.get(String(datetimearr[i][1])) + datetimearr[i][0]);
|
var day = String(instance[0])
|
||||||
|
var timeslot = String(instance[1])
|
||||||
|
var location = String(instance[2])
|
||||||
|
var key = timeslot + "," + location
|
||||||
|
if (dtmap.has(key) && dtmap.get(key)[1] === location) {
|
||||||
|
dtmap.set(key, [dtmap.get(key)[0] + day, location]);
|
||||||
} else {
|
} else {
|
||||||
dtmap.set(String(datetimearr[i][1]), datetimearr[i][0]);
|
dtmap.set(key, [day, location]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dtmap
|
return dtmap
|
||||||
|
|||||||
Reference in New Issue
Block a user