var grades;
var rmpLink;
var next;
var bottom;
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;
var done = true;
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
if (document.querySelector('#fos_fl')) {
let params = (new URL(document.location)).searchParams;
let dep = params.get("fos_fl");
let level = params.get("level");
if (dep && level) {
if (dep.length == 3 && (level == 'U' || level == 'L' || level == 'G')) {
document.querySelector('#fos_fl').value = dep;
document.querySelector('#level').value = level;
}
}
}
next = $("#next_nav_link");
chrome.storage.sync.get('loadAll', function (data) {
if (data.loadAll) {
$('[title*="next listing"]').remove();
}
});
loadDataBase();
//make heading and modal
if (!$("#kw_results_table").length) {
$("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(`
`);
// if ($(this).find('td[data-th="Status"]').text().includes('waitlisted')) {
// $(this).find('td').each(function () {
// $(this).css('background-color', '#E0E0E0');
// });
// }
}
});
}
//update the conflicts
update(0);
/*Handle the button clicks*/
$("tbody").on('click', '#distButton', function () {
var row = $(this).closest('tr');
$('.modal-content').stop().animate({
scrollTop: 0
}, 500);
$(this).blur();
getCourseInfo(row);
getDistribution();
});
$(window).scroll(function () {
if ($(document).height() <= $(window).scrollTop() + $(window).height() + 150) {
loadNextPages();
}
});
$("#myModal").on('click', '#saveCourse', function () {
setTimeout(function () {
saveCourse();
}, 0);
});
$("#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);
});
$("#semesters").on('change', function () {
var sem = $(this).val();
sem = sem == "Aggregate" ? undefined : sem;
getDistribution(sem);
});
$("#retry").click(function () {
$("#retrylabel").hide();
$(this).hide();
loadNextPages();
});
$(document).keydown(function (e) {
/*Close Modal when hit escape*/
if (e.keyCode == 27) {
close();
} 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") {
update(0);
}
});
function loadNextPages() {
chrome.storage.sync.get('loadAll', function (data) {
if (data.loadAll) {
let link = next.prop('href');
if (done && next && link) {
$("#nextlabel").css('display', 'inline-block');
$('#loader').css('display', 'inline-block');
done = false;
$.get(link, function (response) {
if (response) {
var nextpage = $('').html(response).contents();
var current = $('tbody');
var oldlength = $('tbody tr').length;
// console.log(oldlength);
var last = current.find('.course_header>h2:last').text();
// console.log(last);
next = nextpage.find("#next_nav_link");
done = true;
$("#nextlabel").hide();
$('#loader').hide();
var newrows = [];
nextpage.find('tbody>tr').each(function () {
let hasCourseHead = $(this).find('td').hasClass("course_header");
if (!(hasCourseHead && $(this).has('th').length == 0)) {
$(this).append(`
`);
// if ($(this).find('td[data-th="Status"]').text().includes('waitlisted')) {
// $(this).find('td').each(function () {
// $(this).css('background-color', '#E0E0E0');
// });
// }
}
if (!(hasCourseHead && last == $(this).find('td').text())) {
newrows.push($(this));
}
});
current.append(newrows);
// console.log($('tbody tr').length + " " + $('tr>td.course_header').length);
// update(oldlength + 1);
update(oldlength + 1)
}
}).fail(function () {
done = true;
$("#nextlabel").hide();
$('#loader').hide();
$("#retrylabel").css('display', 'inline-block');
$('#retry').css('display', 'inline-block');
});
}
}
});
}
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);
setTimeout(function () {
$("#snackbar").attr("class", "show");
}, 200);
setTimeout(function () {
$("#snackbar").attr("class", "");
}, 3000);
chrome.runtime.sendMessage({
command: "updateCourseList"
});
});
}
/* 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(start) {
chrome.storage.sync.get('courseConflictHighlight', function (data) {
var red = 0;
var black = 0;
var green = 0;
$('table').find('tr').each(function (i) {
if (i >= start) {
if (!($(this).find('td').hasClass("course_header")) && $(this).has('th').length == 0) {
var thisForm = this;
var uniquenum = $(this).find('td[data-th="Unique"]').text();
// console.log(uniquenum);
chrome.runtime.sendMessage({
command: "isSingleConflict",
dtarr: getDtarr(this),
unique: uniquenum
}, function (response) {
var tds = $(thisForm).find('td');
// console.log(tds.css('color'));
if (response.isConflict && data.courseConflictHighlight && !response.alreadyContains) {
if (tds.css('color') != 'rgb(244, 67, 54)') {
console.log('made red ' + uniquenum);
red++;
tds.css('color', '#F44336').css('text-decoration', 'line-through').css('font-weight', 'normal');
}
} else if (!response.alreadyContains) {
if (tds.css('color') != 'rgb(51, 51, 51)') {
console.log('made black ' + uniquenum);
black++;
tds.css('color', 'black').css('text-decoration', 'none').css('font-weight', 'normal');
}
}
if (response.alreadyContains) {
if (tds.css('color') != 'rgb(76, 175, 80)') {
green++;
console.log('made green ' + uniquenum);
tds.css('color', '#4CAF50').css('text-decoration', 'none').css('font-weight', 'bold');
}
}
});
}
}
});
//console.log(`red: ${red} black: ${black} green: ${green}`);
});
}
/* 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) {
console.log('WHAT');
semesterCode = new URL(window.location.href).pathname.split('/')[4];
$("h2.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 = [];
var lines = [];
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();
lines.push($(`