var courses; // get the courses from storage setCourseList(); // var modhtml = '
►
" + text + ">").prependTo("#courseList").hide().fadeIn(200);
}
});
}
/* Handle the button clicks */
$(document).ready(function () {
$("#courseList").on('mouseover', '.copybut', function () {
$(this).addClass('shadow');
}).on('mouseleave', '.copybut', function () {
$(this).removeClass('shadow');
});
$("#courseList").on('click', '.copybut', function (e) {
e.stopPropagation();
var temp = $("");
$(this).find('i').text('check');
$(this).stop(true, false).removeAttr('style').removeClass('shadow', {
duration: 200
});
$(this).find('i').delay(400).queue(function (n) {
$(this).text('content_copy');
$(this).parent().removeClass('shadow');
if ($(this).parent().is(":hover")) {
$(this).parent().addClass('shadow');
}
n();
})
$("body").append(temp);
temp.val($(this).val()).select();
document.execCommand("copy");
temp.remove();
});
$("#courseList").on('click', 'li', function () {
$(this).find("#listMoreInfo").click(function () {
window.open(courses[$(this).closest("li").attr("id")].link);
});
let status = courses[$(this).closest("li").attr("id")].status;
let registerlink = courses[$(this).closest("li").attr("id")].registerlink;
if (status.includes("closed") || status.includes("cancelled") || !status || !registerlink) {
$(this).find("#register").text("Can't Register").css("background-color", "#FF5722");
} else {
if (status.includes("waitlisted")) {
$(this).find("#register").text("Join Waitlist").css("background-color", "#FF9800");
} else {
$(this).find("#register").text("Register").css("background-color", "#4CAF50");
}
$(this).find("#register").click(function () {
chrome.tabs.query({
currentWindow: true,
active: true
}, function (tab) {
chrome.tabs.update(tab.id, {
url: registerlink
});
});
})
}
/* clear the conflict messages, then remove the course and updateConflicts. update the tabs*/
$(this).find("#listRemove").click(function () {
var thisForm = this;
if (canremove) {
canremove = false;
$(thisForm).closest("ul").find("#conflict").fadeOut(300, function () {
$(this).remove();
});
chrome.runtime.sendMessage({
command: "courseStorage",
course: courses[$(thisForm).closest("li").attr("id")],
action: "remove"
}, function (response) {
$(thisForm).closest("li").fadeOut(200);
if ($(thisForm).closest("ul").children(':visible').length === 1) {
showEmpty();
}
canremove = true;
console.log('computedconflicts');
updateConflicts();
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(tabs[i].id, {
command: "updateCourseList"
});
}
});
});
}
});
/* Show the times popout and more info options*/
if ($(this).find("#moreInfo").is(":hidden")) {
$(this).find("#moreInfo").fadeIn(200);
$(this).find('#arrow').css('transform', 'rotate(90deg)');
} else {
$(this).find("#moreInfo").fadeOut(200);
$(this).find('#arrow').css('transform', '');
}
});
$("#clear").click(function () {
clear();
});
$("#schedule").click(function () {
chrome.tabs.create({
'url': 'https://registrar.utexas.edu/schedules'
});
});
$("#impexp").click(function () {
// Close import export window
if ($("#impexp>i").text() == 'close') {
hideImportExportPopup();
// $(this).removeClass('selected');
} else {
// Open import export window
// If search window open, close it first to prevent overlap
if ($("#search>i").text() == 'close') {
hideSearchPopup();
}
showImportExportPopup();
// $(this).addClass('selected');
}
});
$("#search").click(function () {
// Close search window
if ($("#search>i").text() == 'close') {
hideSearchPopup();
// $(this).removeClass('selected');
} else {
// Open search window
// If import export window open, close it first to prevent overlap
if ($("#impexp>i").text() == 'close') {
hideImportExportPopup();
}
showSearchPopup();
// $(this).addClass('selected');
}
});
$('#import-class').click(function () {
$("#importOrig").click();
});
$('#export-class').click(function () {
chrome.storage.sync.get('savedCourses', function (data) {
if (data.savedCourses.length > 0) {
var exportlink = document.createElement('a');
var url = window.URL.createObjectURL(new Blob([JSON.stringify(data.savedCourses, null, 4)], {
type: "octet/stream"
}));
exportlink.setAttribute('href', url);
exportlink.setAttribute('download', 'my_courses.json');
exportlink.click();
} else {
alert('No Saved Courses to Export.');
}
});
});
$("#search-class").click(() => {
var uniqueId = $("#class_id_input").val();
if (!isNaN(uniqueId)) {
if (uniqueId.length == 5) {
let selectedSemester = $("#semesters").find(":selected").val();
openCoursePage(selectedSemester, uniqueId);
$("#class_id_input").val('');
return;
}
}
alert("Oops, check your input. Class IDs should have 5 digits!");
});
$("#open").click(function () {
chrome.tabs.create({
'url': "options.html"
});
});
$("#calendar").click(function () {
chrome.tabs.create({
'url': "calendar.html"
});
});
});
$("#importOrig").change(function (e) {
var files = e.target.files;
var reader = new FileReader();
reader.onload = function () {
try {
var impCourses = JSON.parse(this.result);
console.log(impCourses);
if (impCourses && impCourses.length && (impCourses.length == 0 || validateObject(impCourses))) {
chrome.storage.sync.set({
savedCourses: impCourses
});
chrome.runtime.sendMessage({
command: "updateBadge"
});
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(tabs[i].id, {
command: "updateCourseList"
});
}
});
setCourseList();
chrome.runtime.sendMessage({
command: "updateStatus",
});
}
} catch (err) {
}
importOrig.value = '';
}
reader.readAsText(files[0]);
});
function validateObject(impCourses) {
for (var i = 0; i < impCourses.length; i++) {
var course = impCourses[i];
var isValid = true;
var props = ["coursename", "datetimearr", "link", "profname", "status", "unique"];
console.log(course.coursename);
for (let j = 0; j < props.length; j++) {
isValid &= course.hasOwnProperty(props[j]);
}
console.log(isValid);
if (!isValid) {
return false;
}
}
return true;
}
/* convert from the dtarr and maek the time lines*/
function makeLine(index) {
var datetimearr = courses[index].datetimearr;
//converted times back
var dtmap = new Map([]);
for (var i = 0; i < datetimearr.length; i++) {
datetimearr[i][1][0] = moment(datetimearr[i][1][0], ["HH:mm"]).format("h:mm a");
datetimearr[i][1][1] = moment(datetimearr[i][1][1], ["HH:mm"]).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]);
} else {
dtmap.set(String(datetimearr[i][1]), datetimearr[i][0]);
}
}
var output = "";
var timearr = Array.from(dtmap.keys());
var dayarr = Array.from(dtmap.values());
if (timearr.length == 0) {
output = "This class has no meeting times."
} else {
for (var i = 0; i < dayarr.length; i++) {
var place = findLoc(dayarr[i], timearr[i], datetimearr);
var building = place.substring(0, place.search(/\d/) - 1);
if (building == "") {
building = "Undecided Location";
}
output += `${dayarr[i]}:${timearr[i].split(",")[0]} to ${timearr[i].split(",")[1]}${place}
`;
}
}
return output;
}
//find the location of a class given its days and timearrs.
function findLoc(day, timearr, datetimearr) {
for (let i = 0; i < datetimearr.length; i++) {
var dtl = datetimearr[i];
// console.log(dtl[1]);
// console.log(timearr);
if (day.includes(dtl[0])) {
if (JSON.stringify(timearr) == JSON.stringify(fixDtl1(dtl[1]))) {
return dtl[2];
}
}
}
}
function fixDtl1(dtl1) {
let output = "";
for (let i = 0; i < dtl1.length; i++) {
output += dtl1[i];
if (i != dtl1.length - 1) {
output += ",";
}
}
return output;
}
/*Clear the list and the storage of courses*/
function clear() {
chrome.storage.sync.set({
savedCourses: []
});
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(tabs[i].id, {
command: "updateCourseList"
});
}
});
chrome.runtime.sendMessage({
command: "updateBadge"
});
$("#courseList").empty()
console.log("cleared");
showEmpty();
}
function getSemesters() {
var schedulelist = 'https://registrar.utexas.edu/schedules';
$.get(schedulelist, function (response) {
if (response) {
var object = $('