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
|
||||
function getCurrentSemesters() {
|
||||
$.get("https://registrar.utexas.edu/schedules", function (response) {
|
||||
if (response) {
|
||||
htmlToNode(response)
|
||||
.find(".callout2>ul>li>a")
|
||||
.each(function (i) {
|
||||
// only show as many semesters as we want to display
|
||||
if (i < Popup.num_semesters) {
|
||||
let sem_name = $(this).text().trim();
|
||||
if (sem_name != "Course Schedule Archive") {
|
||||
// $("#semesters").append(`<option>${sem_name}</option>`);
|
||||
current_semesters[sem_name] = "code";
|
||||
$.get($(this).attr("href"), function (response) {
|
||||
if (response) {
|
||||
let response_node = htmlToNode(response);
|
||||
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) {
|
||||
current_semesters[name] = sem_num;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
async function getCurrentSemesters() {
|
||||
let webData;
|
||||
if(Object.keys(current_semesters).length > 0) {
|
||||
chrome.storage.local.set({
|
||||
semesterCache: current_semesters
|
||||
});
|
||||
}
|
||||
async function goFetch(linkend="") {
|
||||
console.log("lk " + linkend)
|
||||
return fetch("https://registrar.utexas.edu/schedules/" + linkend)
|
||||
.then((response) => {
|
||||
return response.text()
|
||||
.then((data) => {
|
||||
return data;
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
await goFetch().then((data) => {webData = data});
|
||||
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
|
||||
|
||||
20
js/import.js
20
js/import.js
@@ -16,7 +16,7 @@ $(function () {
|
||||
$("#import").click(function () {
|
||||
search_nodes = waitlist ? $(".tbg").last().find(".tbon>td:first-child") : $("tr>td:first-child");
|
||||
$(search_nodes).each(function () {
|
||||
importCourse($(this));
|
||||
importCourse($(this), true);
|
||||
})
|
||||
importButtonAnimation($(this));
|
||||
});
|
||||
@@ -24,7 +24,7 @@ $(function () {
|
||||
$("#import_waitlist").click(function () {
|
||||
search_nodes = $("tr.tb span:first-child");
|
||||
$(search_nodes).each(function () {
|
||||
importCourse($(this));
|
||||
importCourse($(this), false);
|
||||
})
|
||||
importButtonAnimation($(this));
|
||||
});
|
||||
@@ -61,17 +61,17 @@ function importButtonAnimation(button) {
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function importCourse(unique_node) {
|
||||
let unique = $(unique_node).text().replace(/\s/g, '');
|
||||
function importCourse(unique_node, force) {
|
||||
let unique = $(unique_node).text().replace(/\s/g, '').substring(0,5);
|
||||
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) {
|
||||
if (response) {
|
||||
let simp_course = buildSimplifiedCourseObject(response, link);
|
||||
let simp_course = buildSimplifiedCourseObject(response, link, force);
|
||||
chrome.runtime.sendMessage({
|
||||
command: "courseStorage",
|
||||
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 {
|
||||
full_name,
|
||||
@@ -97,7 +97,9 @@ function buildSimplifiedCourseObject(response, link) {
|
||||
register
|
||||
} = 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);
|
||||
}
|
||||
|
||||
|
||||
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*/
|
||||
function convertDateTimeArrToLine(datetimearr) {
|
||||
var output = [];
|
||||
console.log(datetimearr)
|
||||
var dtmap = makeDateTimeMap(datetimearr);
|
||||
var timearr = Array.from(dtmap.keys());
|
||||
var dayarr = Array.from(dtmap.values());
|
||||
console.log(timearr);
|
||||
console.log(dayarr);
|
||||
var temporary = Array.from(dtmap.values())
|
||||
var 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++) {
|
||||
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();
|
||||
building = building ? building : "Undecided Location"
|
||||
var timearrsplit = timearr[i].split(',')
|
||||
output.push({
|
||||
"days": dayarr[i],
|
||||
"start_time": timearr[i].split(",")[0],
|
||||
"end_time": timearr[i].split(',')[1],
|
||||
"start_time": timearrsplit[0],
|
||||
"end_time": timearrsplit[1],
|
||||
"location_link": `https://maps.utexas.edu/buildings/UTM/${building}`,
|
||||
"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");
|
||||
}
|
||||
for (var i = 0; i < datetimearr.length; i++) {
|
||||
if (dtmap.has(String(datetimearr[i][1]))) {
|
||||
dtmap.set(String(datetimearr[i][1]), dtmap.get(String(datetimearr[i][1])) + datetimearr[i][0]);
|
||||
var instance = datetimearr[i]
|
||||
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 {
|
||||
dtmap.set(String(datetimearr[i][1]), datetimearr[i][0]);
|
||||
dtmap.set(key, [day, location]);
|
||||
}
|
||||
}
|
||||
return dtmap
|
||||
|
||||
Reference in New Issue
Block a user