cleaned up code

This commit is contained in:
Sriram Hariharan
2019-08-11 10:09:59 -05:00
parent e877ecaa6b
commit 893e882377
9 changed files with 127 additions and 142 deletions

View File

@@ -308,21 +308,17 @@ function updateStatus(sendResponse) {
var object = $('<div/>').html(result).contents();
let newstatus = object.find('[data-th="Status"]').text();
let registerlink = object.find('td[data-th="Add"] a');
if (registerlink) {
if (registerlink)
registerlink = registerlink.attr('href');
}
var haschanged = (newstatus == oldstatus && registerlink == oldlink);
if (!haschanged) {
if (!haschanged)
console.log(c.unique + ' updated from ' + oldstatus + " to " + newstatus + " and " + oldlink + " to " + registerlink);
}
nochange &= haschanged;
c.registerlink = registerlink;
c.status = newstatus;
}
}
});
} catch (e) {
console.log(e);
console.log('Not logged into UT Coursebook. Could not update class statuses.');
@@ -333,9 +329,6 @@ function updateStatus(sendResponse) {
savedCourses: courses
});
console.log('updated status');
} else {
// console.log('no change');
}
// console.log("updated status' and registerlinks");
});
}

View File

@@ -11,8 +11,6 @@ var curr_course = {}
$("#calendar").after(Template.calendarModal());
chrome.storage.sync.get("savedCourses", function (data) {
// Iterate through each saved course and add to 'event'
saved_courses = data.savedCourses;
@@ -75,14 +73,13 @@ function setUpModal() {
function setRegisterButton(status, registerlink) {
if (canNotRegister(status, registerlink))
$("#register").text("Can't Register").css("background-color", "#FF5722");
$("#register").text("Can't Register").css("background-color", Colors.closed);
else if (status.includes("waitlisted"))
$("#register").text("Join Waitlist").css("background-color", "#FF9800");
$("#register").text("Join Waitlist").css("background-color", Colors.waitlisted);
else
$("#register").text("Register").css("background-color", "#4CAF50");
$("#register").text("Register").css("background-color", Colors.open);
}
function canNotRegister(status, registerlink) {
return status.includes("closed") || status.includes("cancelled") || !status || !registerlink
}
@@ -100,15 +97,15 @@ function buildTimeTitle(datetimearr) {
// Iterate through each saved course and add to 'event'
function buildEventSource(savedCourses) {
function buildEventSource(saved_courses) {
color_counter = 0;
let event_source = [];
var hours = 0;
for (let i = 0; i < savedCourses.length; i++) {
for (let i = 0; i < saved_courses.length; i++) {
let {
coursename,
datetimearr
} = savedCourses[i];
} = saved_courses[i];
let number = seperateCourseNameParts(coursename).number;
hours += parseInt(number.charAt(0));
for (let j = 0; j < datetimearr.length; j++) {
@@ -118,11 +115,15 @@ function buildEventSource(savedCourses) {
}
color_counter++;
}
$("#hours").text(hours + " Hours");
$("#num").text(savedCourses.length + " Courses");
displayMetaData(hours, saved_courses);
return event_source;
}
function displayMetaData(hours, saved_courses) {
$("#hours").text(hours + " Hours");
$("#num").text(saved_courses.length + " Courses");
}
//create the event object for every section
function setEventForSection(session, colorCounter, i) {
let full_day = days.get(session[0]);
@@ -178,8 +179,6 @@ chrome.runtime.onMessage.addListener(
);
$("#info").click(() => {
setTimeout(() => {
window.open(curr_course.link);

View File

@@ -11,8 +11,14 @@ class Colors {
'#FF5252', '#E91E63', '#009688', '#00BCD4',
'#4E342E', '#424242', '#9E9E9E'
];
}
static open = "#4CAF50";
static waitlisted = "#FF9800";
static closed = "#FF5722";
static highlight_conflict = "#F44336";
static highlight_default = "#333333";
static highlight_saved = "#4CAF50";
}
class Export {
static png_options = {
@@ -21,4 +27,9 @@ class Export {
removeContainer: true,
async: true,
}
}
class Text {
}

View File

@@ -1,8 +1,10 @@
console.log(`UT Registration Plus is running on this page: ${window.location.href}`);
var curr_course = {}
var semesterCode = new URL(window.location.href).pathname.split('/')[4];
var doneLoading = true;
var semester_code = new URL(window.location.href).pathname.split('/')[4];
var done_loading = true;
updateListConflictHighlighting();
@@ -64,45 +66,6 @@ $("body").on('click', '#distButton', function () {
getDistribution(curr_course);
});
$("#myModal").on('click', '#saveCourse', function () {
setTimeout(function () {
saveCourse();
}, 0);
});
$("#Syllabi").click(function () {
setTimeout(function () {
window.open(curr_course["links"]["syllabi"]);
}, Timing.button_delay);
});
$("#rateMyProf").click(function () {
setTimeout(function () {
window.open(curr_course["links"]["rate_my_prof"]);
}, Timing.button_delay);
});
$("#eCIS").click(function () {
setTimeout(function () {
window.open(curr_course["links"]["ecis"]);
}, Timing.button_delay);
});
$("#textbook").click(function () {
setTimeout(function () {
window.open(curr_course["links"]["textbook"]);
}, Timing.button_delay);
});
$("#semesters").on('change', function () {
let sem = $(this).val();
sem = sem == "Aggregate" ? undefined : sem;
getDistribution(curr_course, sem);
});
$("#retry").click(function () {
$("#retrylabel").hide();
$(this).hide();
loadNextPages();
});
function updateLinks(course_info, first_name) {
let {
@@ -124,7 +87,7 @@ function buildCourseLinks(course_info) {
prof_name
} = course_info
links = {
"textbook": `https://www.universitycoop.com/adoption-search-results?sn=${semesterCode}__${department}__${number}__${unique}`,
"textbook": `https://www.universitycoop.com/adoption-search-results?sn=${semester_code}__${department}__${number}__${unique}`,
"syllabi": `https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?semester=&department=${department}&course_number=${number}&course_title=&unique=&instructor_first=&instructor_last=${prof_name}&course_type=In+Residence&search=Search`,
//default ones (before first name can be used)
"rate_my_prof": "http://www.ratemyprofessors.com/campusRatings.jsp?sid=1255",
@@ -221,18 +184,18 @@ function updateListConflictHighlighting(start = 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();
var this_form = this;
var unique = $(this).find('td[data-th="Unique"]').text();
chrome.runtime.sendMessage({
command: "isSingleConflict",
dtarr: getDayTimeArray(this),
unique: uniquenum
unique: unique
}, function (response) {
let {
isConflict,
alreadyContains
} = response
updateTextHighlighting($(thisForm).find('td'), canHighlight, isConflict, alreadyContains);
updateTextHighlighting($(this_form).find('td'), canHighlight, isConflict, alreadyContains);
});
}
}
@@ -241,23 +204,24 @@ function updateListConflictHighlighting(start = 0) {
}
function updateTextHighlighting(tds, canHighlight, isConflict, alreadyContains) {
let current_color = rgb2hex(tds.css('color'));
if (isConflict && canHighlight && !alreadyContains) {
if (tds.css('color') != 'rgb(244, 67, 54)')
tds.css('color', '#F44336').css('text-decoration', 'line-through').css('font-weight', 'normal');
if (current_color != Colors.highlight_conflict)
tds.css('color', Colors.highlight_conflict).css('text-decoration', 'line-through').css('font-weight', 'normal');
} else if (!alreadyContains) {
if (tds.css('color') != 'rgb(51, 51, 51)')
tds.css('color', 'black').css('text-decoration', 'none').css('font-weight', 'normal');
if (tds.css('color') != Colors.highlight_default)
tds.css('color', Colors.highlight_default).css('text-decoration', 'none').css('font-weight', 'normal');
}
if (alreadyContains) {
if (tds.css('color') != 'rgb(76, 175, 80)')
tds.css('color', '#4CAF50').css('text-decoration', 'none').css('font-weight', 'bold');
if (tds.css('color') != Colors.highlight_saved)
tds.css('color', Colors.highlight_saved).css('text-decoration', 'none').css('font-weight', 'bold');
}
}
/* For a row, get the date-time-array for checking conflicts*/
function getDayTimeArray(row, course_info) {
var daytimearray = []
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());
@@ -268,20 +232,20 @@ function getDayTimeArray(row, course_info) {
for (var j = 0; j < date.length; j++) {
let letter = date.charAt(j);
if (letter == "T" && j < date.length - 1 && date.charAt(j + 1) == "H") {
daytimearray.push(["TH", convertTime(time), place]);
day_time_array.push(["TH", convertTime(time), place]);
} else {
if (letter != "H")
daytimearray.push([letter, convertTime(time), place]);
day_time_array.push([letter, convertTime(time), place]);
}
}
}
return daytimearray;
return day_time_array;
}
function convertDateTimeArrToLine(date, time, place) {
var arr = seperateDays(date)
var output = prettifyDaysText(arr)
var building = place.substring(0, place.search(/\d/) - 1);
let arr = seperateDays(date)
let output = prettifyDaysText(arr)
let building = place.substring(0, place.search(/\d/) - 1);
building = building == "" ? "Undecided Location" : building;
return `${output} at ${time.replace(/\./g, '').replace(/\-/g, ' to ')} in <a style='font-size:medium' target='_blank' href='https://maps.utexas.edu/buildings/UTM/${building}'>${building}</>`;
}
@@ -319,9 +283,8 @@ function buildTimeTitle(course_info) {
times,
places
} = course_info["time_data"]
datetimearr = [];
var lines = [];
for (var i = 0; i < days.length; i++) {
for (let i = 0; i < days.length; i++) {
var date = days[i];
var time = times[i];
var place = places[i];
@@ -382,7 +345,6 @@ function openDialog(course_info, res) {
//close button
allowClosing();
setChart(data);
}
function setChart(data) {
@@ -468,26 +430,26 @@ function loadNextPages() {
chrome.storage.sync.get('loadAll', function (data) {
if (data.loadAll) {
let link = next.prop('href');
if (doneLoading && next && link) {
if (done_loading && next && link) {
toggleLoadingPage(true);
$.get(link, function (response) {
if (response) {
var nextpage = $('<div/>').html(response).contents();
var next_page = $('<div/>').html(response).contents();
var current = $('tbody');
var oldlength = $('tbody tr').length;
var old_length = $('tbody tr').length;
var last = current.find('.course_header>h2:last').text();
next = nextpage.find("#next_nav_link");
next = next_page.find("#next_nav_link");
toggleLoadingPage(false);
var newrows = [];
nextpage.find('tbody>tr').each(function () {
let hasCourseHead = $(this).find('td').hasClass("course_header");
if (!(hasCourseHead && $(this).has('th').length == 0))
var new_rows = [];
next_page.find('tbody>tr').each(function () {
let has_course_header = $(this).find('td').hasClass("course_header");
if (!(has_course_header && $(this).has('th').length == 0))
$(this).append(Template.extensionButton());
if (!(hasCourseHead && last == $(this).find('td').text()))
newrows.push($(this));
if (!(has_course_header && last == $(this).find('td').text()))
new_rows.push($(this));
});
current.append(newrows);
updateListConflictHighlighting(oldlength + 1)
current.append(new_rows);
updateListConflictHighlighting(old_length + 1)
}
}).fail(function () {
toggleLoadingPage(false);
@@ -499,7 +461,43 @@ function loadNextPages() {
});
}
$("#myModal").on('click', '#saveCourse', function () {
setTimeout(function () {
saveCourse();
}, 0);
});
$("#Syllabi").click(function () {
setTimeout(function () {
window.open(curr_course["links"]["syllabi"]);
}, Timing.button_delay);
});
$("#rateMyProf").click(function () {
setTimeout(function () {
window.open(curr_course["links"]["rate_my_prof"]);
}, Timing.button_delay);
});
$("#eCIS").click(function () {
setTimeout(function () {
window.open(curr_course["links"]["ecis"]);
}, Timing.button_delay);
});
$("#textbook").click(function () {
setTimeout(function () {
window.open(curr_course["links"]["textbook"]);
}, Timing.button_delay);
});
$("#semesters").on('change', function () {
let sem = $(this).val();
sem = sem == "Aggregate" ? undefined : sem;
getDistribution(curr_course, sem);
});
$("#retry").click(function () {
$("#retrylabel").hide();
$(this).hide();
loadNextPages();
});
/*Listen for update mssage coming from popup*/
chrome.runtime.onMessage.addListener(
@@ -513,11 +511,11 @@ chrome.runtime.onMessage.addListener(
function toggleLoadingPage(loading) {
if (loading) {
doneLoading = false;
done_loading = false;
$('#loader').css('display', 'inline-block');
$("#nextlabel").css('display', 'inline-block');
} else {
doneLoading = true;
done_loading = true;
$('#loader').hide();
$("#nextlabel").hide();
}

View File

@@ -6,24 +6,23 @@ $(function () {
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){
if (waitlist) {
sem = $('[name="s_ccyys"]').val();
$("[href='#top']").before(importbutton);
} else {
sem = $("option[selected='selected']").val();
$("table").after(importbutton);
}
console.log(sem);
$("#import").prepend("<div id='snackbar'>defaultmessage..</div>");
$("#import").click(function () {
if(waitlist){
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(){
$("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();

View File

@@ -6,26 +6,20 @@ const days = new Map([
["F", "Friday"]
]);
const semOrder = {
"Spring": 0,
"Fall": 1,
"Summer": 2,
"Winter": 3
}
function getStatusColor(status) {
let color = "black";
if (status.includes("open")) {
color = "#4CAF50";
color = Colors.open;
} else if (status.includes("waitlisted")) {
color = "#FF9800"
color = Colors.waitlisted;
} else if (status.includes("closed") || status.includes("cancelled")) {
color = "#FF5722";
color = Colors.closed;
}
return color;
}
function buildQuery(course_data, sem) {
let query = !sem ? "select * from agg" : "select * from grades";
query += " where dept like '%" + course_data["department"] + "%'";
@@ -106,6 +100,12 @@ function prettifyDaysText(arr) {
function semesterSort(semA, semB) {
let semOrder = {
"Spring": 0,
"Fall": 1,
"Summer": 2,
"Winter": 3
}
let aName = semA.split(' ')[0];
let aYear = parseInt(semA.split(' ')[1]);
let bName = semB.split(' ')[0];
@@ -298,4 +298,13 @@ function reformatDateTime(dtl1) {
}
}
return output;
}
function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}

View File

@@ -144,8 +144,6 @@ function buildTimeTitle(times) {
return lines
}
function makeLine(date, time, place) {
var arr = seperateDays(date)
var output = prettifyDaysText(arr)
@@ -154,28 +152,6 @@ function makeLine(date, time, place) {
return `${output} at ${time.replace(/\./g, '').replace(/\-/g, ' to ')} in <a style='font-size:medium' target='_blank' href='https://maps.utexas.edu/buildings/UTM/${building}'>${building}</>`;
}
function prettifyDaysText(arr) {
var output = "";
if (arr.length > 2) {
for (var i = 0; i < arr.length; i++) {
if (i < arr.length - 1)
output += arr[i] + ", "
if (i == arr.length - 2)
output += "and ";
if (i == arr.length - 1)
output += arr[i];
}
} else if (arr.length == 2) {
output = arr[0] + " and " + arr[1];
} else {
output = arr[0];
}
return output
}
function setChart(data) {
//set up the chart
toggleChartLoading(false);