refactored import
This commit is contained in:
@@ -144,4 +144,13 @@ class Template {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Import = class Import {
|
||||
|
||||
static button_text_default = "<span style='font-size:small'>Import to </span><b>UT Reg Plus<b>";
|
||||
static import_button() {
|
||||
return `<button class='matbut' id='import' style='margin:20px 0px 20px 0px;'>${this.button_text_default}</button><br>`;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -413,7 +413,8 @@ function getDescription(course_info) {
|
||||
url: course_info["individual"],
|
||||
success: function (response) {
|
||||
if (response) {
|
||||
description_lines = htmlToNode(response).find('#details > p').toArray().map(x => $(x).text());
|
||||
let response_node = htmlToNode(response);
|
||||
description_lines = response_node.find('#details > p').toArray().map(x => $(x).text());
|
||||
displayDescription(buildFormattedDescription(description_lines));
|
||||
let first_name = extractFirstName(response_node);
|
||||
updateLinks(course_info, first_name);
|
||||
|
||||
177
js/import.js
177
js/import.js
@@ -1,66 +1,45 @@
|
||||
var link;
|
||||
var waitlist;
|
||||
var sem;
|
||||
$(function () {
|
||||
//template https://utdirect.utexas.edu/apps/registrar/course_schedule/20189/51475/
|
||||
console.log(window.location.href);
|
||||
var importbutton = "<button class='matbut' id='import' style='margin:20px 0px 20px 0px;'><span style='font-size:small'>Import into </span><b>UT Reg Plus<b></h2></button><br>";
|
||||
waitlist = !(window.location.href.includes('https://utdirect.utexas.edu/registration/classlist.WBX'));
|
||||
if (waitlist) {
|
||||
sem = $('[name="s_ccyys"]').val();
|
||||
$("[href='#top']").before(importbutton);
|
||||
} else {
|
||||
sem = $("option[selected='selected']").val();
|
||||
$("table").after(importbutton);
|
||||
}
|
||||
$("#import").prepend("<div id='snackbar'>defaultmessage..</div>");
|
||||
$("#import").click(function () {
|
||||
if (waitlist) {
|
||||
$(".tbg").last().find(".tbon>td:first-child").each(function () {
|
||||
let unique = $(this).text().replace(/\s/g, '');
|
||||
link = `https://utdirect.utexas.edu/apps/registrar/course_schedule/${sem}/${unique}/`;
|
||||
getInfo();
|
||||
});
|
||||
} else {
|
||||
$("tr>td:first-child").each(function () {
|
||||
let unique = $(this).text().replace(/\s/g, '');
|
||||
link = `https://utdirect.utexas.edu/apps/registrar/course_schedule/${sem}/${unique}/`;
|
||||
getInfo();
|
||||
});
|
||||
}
|
||||
$("#import").text("Courses Saved!").css("background-color", "#4CAF50");
|
||||
setTimeout(function () {
|
||||
$("#import").html("<span style='font-size:small'>Import into </span><b>UT Reg Plus<b></h2>").css("background-color", "#FF9800");
|
||||
}, 1000);
|
||||
});
|
||||
sem = waitlist ? $('[name="s_ccyys"]').val() : $("option[selected='selected']").val();
|
||||
if (waitlist)
|
||||
$("[href='#top']").before(Template.Import.import_button());
|
||||
else
|
||||
$("table").after(Template.Import.import_button());
|
||||
$("#import").prepend("<div id='snackbar'>import snackbar..</div>");
|
||||
|
||||
$("#import").click(function () {
|
||||
search_nodes = waitlist ? $(".tbg").last().find(".tbon>td:first-child") : $("tr>td:first-child");
|
||||
$(search_nodes).each(function () {
|
||||
importCourse($(this));
|
||||
})
|
||||
importButtonAnimation();
|
||||
});
|
||||
});
|
||||
|
||||
/*Course object for passing to background*/
|
||||
function Course(coursename, unique, profname, datetimearr, status, link, registerlink) {
|
||||
this.coursename = coursename;
|
||||
this.unique = unique;
|
||||
this.profname = profname;
|
||||
this.datetimearr = datetimearr;
|
||||
this.status = status;
|
||||
this.link = link;
|
||||
this.registerlink = registerlink;
|
||||
|
||||
function importButtonAnimation() {
|
||||
$("#import").text("Courses Saved!").css("background-color", Colors.open);
|
||||
setTimeout(function () {
|
||||
$("#import").html(Template.Import.button_text_default).css('background-color', Colors.waitlisted);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function importCourse(unique_node) {
|
||||
let unique = $(unique_node).text().replace(/\s/g, '');
|
||||
link = `https://utdirect.utexas.edu/apps/registrar/course_schedule/${sem}/${unique}/`;
|
||||
buildAddCourse(link);
|
||||
}
|
||||
|
||||
|
||||
function getInfo(classurl) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", link, false);
|
||||
xhr.send();
|
||||
var response = xhr.responseText;
|
||||
function buildAddCourse(link) {
|
||||
$.get(link, function (response) {
|
||||
if (response) {
|
||||
var output = "";
|
||||
var object = $('<div/>').html(response).contents();
|
||||
var c = getCourseObject(object);
|
||||
console.log(c);
|
||||
let simp_course = buildSimplifiedCourseObject(response);
|
||||
chrome.runtime.sendMessage({
|
||||
command: "courseStorage",
|
||||
course: c,
|
||||
course: simp_course,
|
||||
action: "add"
|
||||
}, function () {
|
||||
chrome.runtime.sendMessage({
|
||||
@@ -68,52 +47,82 @@ function getInfo(classurl) {
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function buildSimplifiedCourseObject(response) {
|
||||
let imported_course = getCourseObject(htmlToNode(response));
|
||||
let {
|
||||
full_name,
|
||||
unique,
|
||||
prof_name,
|
||||
status,
|
||||
individual,
|
||||
register
|
||||
} = curr_course;
|
||||
let dtarr = getDayTimeArray(undefined, curr_course);
|
||||
|
||||
return new Course(full_name, unique, prof_name, dtarr, status, individual, register);
|
||||
}
|
||||
|
||||
/*For a row, get all the course information and add the date-time-lines*/
|
||||
function getCourseObject(object) {
|
||||
let coursename = object.find("#details h2").text();
|
||||
let uniquenum = object.find('td[data-th="Unique"]').text();
|
||||
let profname = object.find("td[data-th='Instructor']").text().split(', ')[0];
|
||||
if (profname.indexOf(" ") == 0) {
|
||||
profname = profname.substring(1);
|
||||
function getCourseObject(response_node) {
|
||||
let course_name = $(response_node).find("#details h2").text();
|
||||
let course_row = $(response_node).find('table');
|
||||
let individual = document.URL;
|
||||
curr_course = buildBasicCourseInfo(course_row, course_name, individual);
|
||||
}
|
||||
|
||||
|
||||
function buildBasicCourseInfo(row, course_name, individual) {
|
||||
let {
|
||||
name,
|
||||
department,
|
||||
number
|
||||
} = seperateCourseNameParts(course_name);
|
||||
let instructor_text = $(row).find('td[data-th="Instructor"]').text();
|
||||
let has_initial = instructor_text.indexOf(',') > 0;
|
||||
course_info = {
|
||||
"full_name": course_name,
|
||||
"name": name,
|
||||
"department": department,
|
||||
"number": number,
|
||||
"individual": individual ? individual : $(row).find('td[data-th="Unique"] a').prop('href'),
|
||||
"register": $(row).find('td[data-th="Add"] a').prop('href'),
|
||||
"unique": $(row).find('td[data-th="Unique"]').text(),
|
||||
"status": $(row).find('td[data-th="Status"]').text(),
|
||||
"prof_name": instructor_text ? has_initial ? capitalizeString(instructor_text.split(', ')[0]) : capitalizeString(instructor_text) : "Undecided",
|
||||
"initial": instructor_text && has_initial ? instructor_text.split(', ')[1].substring(0, 1) : "",
|
||||
"time_data": {
|
||||
"days": $(row).find('td[data-th="Days"]>span').toArray().map(x => $(x).text().trim()),
|
||||
"times": $(row).find('td[data-th="Hour"]>span').toArray().map(x => $(x).text().trim()),
|
||||
"places": $(row).find('td[data-th="Room"]>span').toArray().map(x => $(x).text().trim())
|
||||
},
|
||||
"links": {}
|
||||
}
|
||||
let datetimearr = getDtarr(object);
|
||||
let status = object.find('td[data-th="Status"]').text();
|
||||
let indlink = link;
|
||||
let registerlink = object.find('td[data-th="Add"] a').prop('href');
|
||||
return new Course(coursename, uniquenum, profname, datetimearr, status, indlink, registerlink);
|
||||
return course_info;
|
||||
}
|
||||
|
||||
/* For a row, get the date-time-array for checking conflicts*/
|
||||
function getDtarr(object) {
|
||||
var numlines = object.find('td[data-th="Days"]>span').length;
|
||||
var dtarr = [];
|
||||
for (var i = 0; i < numlines; i++) {
|
||||
var date = object.find('td[data-th="Days"]>span:eq(' + i + ')').text();
|
||||
var time = object.find('td[data-th="Hour"]>span:eq(' + i + ')').text();
|
||||
var place = object.find('td[data-th="Room"]>span:eq(' + i + ')').text();
|
||||
function getDayTimeArray(row, course_info) {
|
||||
var day_time_array = []
|
||||
let days = course_info ? course_info["time_data"]["days"] : $(row).find('td[data-th="Days"]>span').toArray().map(x => $(x).text().trim());
|
||||
let times = course_info ? course_info["time_data"]["times"] : $(row).find('td[data-th="Hour"]>span').toArray().map(x => $(x).text().trim());
|
||||
let places = course_info ? course_info["time_data"]["places"] : $(row).find('td[data-th="Room"]>span').toArray().map(x => $(x).text().trim());
|
||||
for (var i = 0; i < days.length; i++) {
|
||||
let date = days[i];
|
||||
let time = times[i];
|
||||
let place = places[i];
|
||||
for (var j = 0; j < date.length; j++) {
|
||||
var letter = date.charAt(j);
|
||||
var day = "";
|
||||
let letter = date.charAt(j);
|
||||
if (letter == "T" && j < date.length - 1 && date.charAt(j + 1) == "H") {
|
||||
dtarr.push(["TH", convertTime(time), place]);
|
||||
day_time_array.push(["TH", convertTime(time), place]);
|
||||
} else {
|
||||
if (letter != "H") {
|
||||
dtarr.push([letter, convertTime(time), place]);
|
||||
if (letter != "H")
|
||||
day_time_array.push([letter, convertTime(time), place]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dtarr;
|
||||
}
|
||||
|
||||
/*Convert time to 24hour format*/
|
||||
function convertTime(time) {
|
||||
var converted = time.replace(/\./g, '').split("-");
|
||||
for (var i = 0; i < 2; i++) {
|
||||
converted[i] = moment(converted[i], ["h:mm A"]).format("HH:mm");
|
||||
}
|
||||
return converted;
|
||||
return day_time_array;
|
||||
}
|
||||
65
js/popup.js
65
js/popup.js
@@ -84,8 +84,8 @@ $("#clear").click(function () {
|
||||
chrome.storage.sync.set({
|
||||
savedCourses: []
|
||||
});
|
||||
$("#courseList").empty();
|
||||
updateAllTabsCourseList();
|
||||
$("#courseList").empty()
|
||||
showEmpty();
|
||||
});
|
||||
|
||||
@@ -291,37 +291,6 @@ function handleMoreInfo(clicked_item, curr_course) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getSemesters() {
|
||||
var schedule_list = 'https://registrar.utexas.edu/schedules';
|
||||
$.get(schedule_list, function (response) {
|
||||
if (response) {
|
||||
htmlToNode(response).find('.callout2>ul>li>a').each(function (i) {
|
||||
if (i < Popup.num_semesters) {
|
||||
let sem_name = $(this).text().trim();
|
||||
if (sem_name != "Course Schedule Archive") {
|
||||
$("#semesters").append(`<option>${sem_name}</option>`);
|
||||
$.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();
|
||||
$("option").each(function () {
|
||||
if ($(this).text() == name)
|
||||
$(this).val(sem_num);
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function handleEmpty() {
|
||||
if (courses.length != 0) {
|
||||
$("#empty").hide();
|
||||
@@ -392,3 +361,35 @@ function showImportExportPopup() {
|
||||
$("#impexp>i").text('close');
|
||||
$("#import-export-popup").removeClass('hide');
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getSemesters() {
|
||||
var schedule_list = 'https://registrar.utexas.edu/schedules';
|
||||
$.get(schedule_list, function (response) {
|
||||
if (response) {
|
||||
htmlToNode(response).find('.callout2>ul>li>a').each(function (i) {
|
||||
if (i < Popup.num_semesters) {
|
||||
let sem_name = $(this).text().trim();
|
||||
if (sem_name != "Course Schedule Archive") {
|
||||
$("#semesters").append(`<option>${sem_name}</option>`);
|
||||
$.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();
|
||||
$("option").each(function () {
|
||||
if ($(this).text() == name)
|
||||
$(this).val(sem_num);
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -28,7 +28,7 @@
|
||||
"matches": ["https://utexas.collegescheduler.com/*"]
|
||||
}, {
|
||||
"css": ["css/styles.css"],
|
||||
"js": ["js/config.js", "js/lib/moment.min.js", "js/lib/sql-memory-growth.js", "js/lib/highcharts.js", "js/lib/jquery-3.3.1.min.js", "js/import.js"],
|
||||
"js": ["js/config.js", "js/lib/moment.min.js", "js/lib/sql-memory-growth.js", "js/lib/highcharts.js", "js/lib/jquery-3.3.1.min.js", "js/Template.js", "js/util.js", "js/import.js"],
|
||||
"matches": ["https://utdirect.utexas.edu/registrar/waitlist/wl_see_my_waitlists.WBX", "https://utdirect.utexas.edu/registration/classlist.WBX*"]
|
||||
}],
|
||||
"web_accessible_resources": [
|
||||
|
||||
Reference in New Issue
Block a user