var grades;
var rmpLink;
var eCISLink;
var textbookLink;
var coursename;
var profname;
var profinit;
var uniquenum;
var profurl;
var registerlink;
var department;
var course_nbr;
var datetimearr = [];
var chart;
var description;
var status;
var semesterCode;
var isIndividual = false;
const days = new Map([
["M", "Monday"],
["T", "Tuesday"],
["W", "Wednesday"],
["TH", "Thursday"],
["F", "Friday"]
]);
const fadetime = 150;
const butdelay = 75;
//This extension may be super lit, but you know what's even more lit?
//Matthew Tran's twitter and insta: @MATTHEWTRANN and @matthew.trann
$(function () {
loadDataBase();
//make heading and modal
$("table thead th:last-child").after('
");
//go through all the rows in the list
$('table').find('tr').each(function () {
if (!($(this).find('td').hasClass("course_header")) && $(this).has('th').length == 0) {
//if a course row, then add the extension button
$(this).append(`
`);
}
});
//update the conflicts
update();
/*Handle the button clicks*/
$(".distButton").click(function () {
var row = $(this).closest('tr');
getCourseInfo(row);
getDistribution();
});
$("#saveCourse").click(function () {
saveCourse();
});
$("#Syllabi").click(function () {
setTimeout(function () {
window.open(`https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?semester=&department=${department}&course_number=${course_nbr}&course_title=&unique=&instructor_first=&instructor_last=${profname}&course_type=In+Residence&search=Search`);
}, butdelay);
});
$("#rateMyProf").click(function () {
setTimeout(function () {
window.open(rmpLink);
}, butdelay);
});
$("#eCIS").click(function () {
setTimeout(function () {
window.open(eCISLink);
}, butdelay);
});
$("#textbook").click(function () {
setTimeout(function () {
window.open(textbookLink);
}, butdelay);
});
$(document).keydown(function (e) {
/*Close Modal when hit escape*/
if (e.keyCode == 27) {
$("#myModal").fadeOut(fadetime);
$("#snackbar").attr("class", "");
} else if (e.keyCode == 13 && $('#myModal').is(':visible')) {
/*save course when hit enter*/
saveCourse();
}
});
/*Listen for update mssage coming from popup*/
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.command == "updateCourseList") {
// console.log("hello");
update();
}
});
});
function saveCourse() {
var c = new Course(coursename, uniquenum, profname, datetimearr, status, profurl, registerlink);
chrome.runtime.sendMessage({
command: "courseStorage",
course: c,
action: $("#saveCourse").text().substring(0, $("#saveCourse").text().indexOf(" ")).toLowerCase()
}, function (response) {
$("#saveCourse").text(response.label);
$("#snackbar").text(response.done);
$("#snackbar").attr("class", "show");
setTimeout(function () {
$("#snackbar").attr("class", "");
}, 3000);
chrome.runtime.sendMessage({
command: "updateCourseList"
}, function () {
update();
});
});
}
/* Update the course list to show if the row contains a course that conflicts with the saved course is one of the saved courses */
function update() {
chrome.storage.sync.get('courseConflictHighlight', function (data) {
$('table').find('tr').each(function () {
if (!($(this).find('td').hasClass("course_header")) && $(this).has('th').length == 0) {
var thisForm = this;
var uniquenum = $(this).find('td[data-th="Unique"]').text();
chrome.runtime.sendMessage({
command: "isSingleConflict",
dtarr: getDtarr(this),
unique: uniquenum
}, function (response) {
if (response.isConflict && data.courseConflictHighlight) {
$(thisForm).find('td').each(function () {
$(this).css('color', '#F44336').css('text-decoration', 'line-through').css('font-weight', 'normal');
});
} else {
$(thisForm).find('td').each(function () {
$(this).css('color', 'black').css('text-decoration', 'none').css('font-weight', 'normal');
});
}
if (response.alreadyContains) {
$(thisForm).find('td').each(function () {
$(this).css('color', '#4CAF50').css('text-decoration', 'none').css('font-weight', 'bold');
});
}
});
}
});
});
}
/* For a row, get the date-time-array for checking conflicts*/
function getDtarr(row) {
var numlines = $(row).find('td[data-th="Days"]>span').length;
var dtarr = [];
for (var i = 0; i < numlines; i++) {
var date = $(row).find('td[data-th="Days"]>span:eq(' + i + ')').text();
var time = $(row).find('td[data-th="Hour"]>span:eq(' + i + ')').text();
var place = $(row).find('td[data-th="Room"]>span:eq(' + i + ')').text();
for (var j = 0; j < date.length; j++) {
var letter = date.charAt(j);
var day = "";
if (letter == "T" && j < date.length - 1 && date.charAt(j + 1) == "H") {
dtarr.push(["TH", convertTime(time), place]);
} else {
if (letter != "H") {
dtarr.push([letter, convertTime(time), place]);
}
}
}
}
return dtarr;
}
/*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;
}
/*For a row, get all the course information and add the date-time-lines*/
function getCourseInfo(row) {
semesterCode = new URL(window.location.href).pathname.split('/')[4];
$(".dateTimePlace").remove();
$('table').find('tr').each(function () {
if ($(this).find('td').hasClass("course_header")) {
coursename = $(this).find('td').text() + "";
}
if ($(this).is(row)) {
profurl = $(this).find('td[data-th="Unique"] a').prop('href');
registerlink = $(this).find('td[data-th="Add"] a').prop('href');
// console.log(registerlink);
uniquenum = $(this).find('td[data-th="Unique"]').text();
status = $(this).find('td[data-th="Status"]').text();
profname = $(this).find('td[data-th="Instructor"]').text().split(', ')[0];
profinit = $(this).find('td[data-th="Instructor"]').text().split(', ')[1];
if (profname.indexOf(" ") == 0) {
profname = profname.substring(1);
}
var numlines = $(this).find('td[data-th="Days"]>span').length;
datetimearr = [];
for (var i = 0; i < numlines; i++) {
var date = $(this).find('td[data-th="Days"]>span:eq(' + i + ')').text();
var time = $(this).find('td[data-th="Hour"]>span:eq(' + i + ')').text();
var place = $(this).find('td[data-th="Room"]>span:eq(' + i + ')').text();
$("#topbuttons").before(`