diff --git a/css/_materialFullCalendar.css b/css/_materialFullCalendar.css index cdc4cc65..84c30310 100644 --- a/css/_materialFullCalendar.css +++ b/css/_materialFullCalendar.css @@ -244,7 +244,7 @@ Colors: Use the following - https://www.google.com/design/spec/style/color.html# #classname { font-weight: bold; margin-bottom: -10px; - font-size: medium; + font-size: large; } .modal-content { @@ -254,7 +254,7 @@ Colors: Use the following - https://www.google.com/design/spec/style/color.html# overflow-y: auto; padding: 20px; border: 1px solid #888; - width: 30%; + width: 35%; } #prof { @@ -266,6 +266,12 @@ Colors: Use the following - https://www.google.com/design/spec/style/color.html# margin: 10px; } +body a:link, +body a:visited { + font-weight: bold; + color: #3c87a3; +} + .time { margin-left: auto; margin-right: auto; diff --git a/js/calendar.js b/js/calendar.js index 4f445890..3df46cd9 100644 --- a/js/calendar.js +++ b/js/calendar.js @@ -13,13 +13,14 @@ $(function () { ]); const fadetime = 150; const butdelay = 75; - $("#calendar").prepend(''); + $("#calendar").prepend(''); // Counter to iterate through material colors to avoid duplicates var colorCounter = 0; // Each schedule needs to store 'TITLE - START TIME - END TIME - COLOR' var classSchedules = []; var savedCourses = []; var currLink = ""; + var currindex = 0; chrome.storage.sync.get("savedCourses", function (data) { // Iterate through each saved course and add to 'event' savedCourses = data.savedCourses; @@ -53,11 +54,12 @@ $(function () { }, eventClick: function (data, event, view) { $("#myModal").fadeIn(fadetime); - currLink = savedCourses[data.index].link; - var currunique = savedCourses[data.index].unique; - $("#classname").html(`${savedCourses[data.index].coursename} (${savedCourses[data.index].unique})`); - $("#timelines").append(makeLine(savedCourses[data.index].datetimearr)); - $("#prof").html(`with ${savedCourses[data.index].profname}`); + currindex = data.index; + currLink = savedCourses[currindex].link; + var currunique = savedCourses[currindex].unique; + $("#classname").html(`${savedCourses[currindex].coursename} (${savedCourses[currindex].unique})`); + $("#timelines").append(makeLine(savedCourses[currindex].datetimearr)); + $("#prof").html(`with ${savedCourses[currindex].profname}`); } }); }); @@ -103,6 +105,25 @@ $(function () { window.open(currLink); }, butdelay); }); + $("#remove").click(() => { + setTimeout(() => { + chrome.runtime.sendMessage({ + command: "courseStorage", + course: savedCourses[currindex], + action: "remove" + }, function (response) { + $("#myModal").fadeOut(fadetime); + updateCalendar(); + chrome.tabs.query({}, function (tabs) { + for (var i = 0; i < tabs.length; i++) { + chrome.tabs.sendMessage(tabs[i].id, { + command: "updateCourseList" + }); + } + }); + }); + }, butdelay); + }); /*Close Modal when hit escape*/ $(document).keydown((e) => { if (e.keyCode == 27) { @@ -189,13 +210,17 @@ $(function () { chrome.runtime.onMessage.addListener( function (request, sender, sendResponse) { if (request.command == "updateCourseList" || request.command == "courseAdded") { - chrome.storage.sync.get("savedCourses", function (data) { - savedCourses = data.savedCourses - setAllEvents(data.savedCourses); - console.log(classSchedules); - $('#calendar').fullCalendar('removeEventSources'); - $("#calendar").fullCalendar('addEventSource', classSchedules, true); - }); + updateCalendar(); } }); + + function updateCalendar() { + chrome.storage.sync.get("savedCourses", function (data) { + savedCourses = data.savedCourses + setAllEvents(data.savedCourses); + console.log(classSchedules); + $('#calendar').fullCalendar('removeEventSources'); + $("#calendar").fullCalendar('addEventSource', classSchedules, true); + }); + } }); \ No newline at end of file diff --git a/js/content.js b/js/content.js index 6d2daa57..f3dc1c9f 100644 --- a/js/content.js +++ b/js/content.js @@ -50,25 +50,7 @@ $(function () { }); $("#saveCourse").click(function () { - var c = new Course(coursename, uniquenum, profname, datetimearr, status, profurl); - 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(); - }); - }); - + saveCourse(); }); $("#Syllabi").click(function () { @@ -86,12 +68,15 @@ $(function () { window.open(eCISLink); }, butdelay); }); - /*Close Modal when hit escape*/ $(document).keydown(function (e) { + /*Close Modal when hit escape*/ if (e.keyCode == 27) { $("#myModal").fadeOut(fadetime); + $("#snackbar").attr("class", ""); + } else if (e.keyCode == 13) { + /*save course when hit enter*/ + saveCourse(); } - $("#snackbar").attr("class", ""); }); /*Listen for update mssage coming from popup*/ chrome.runtime.onMessage.addListener( @@ -103,6 +88,27 @@ $(function () { }); }); +function saveCourse() { + var c = new Course(coursename, uniquenum, profname, datetimearr, status, profurl); + 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) { diff --git a/js/popup.js b/js/popup.js index 9b0b5f5e..7fa0cb58 100644 --- a/js/popup.js +++ b/js/popup.js @@ -1,159 +1,175 @@ var courses; // get the courses from storage -chrome.storage.sync.get('savedCourses', function(data) { +chrome.storage.sync.get('savedCourses', function (data) { //find, build, and show the messages for the conflicts in the saved courses - chrome.runtime.sendMessage({command: "checkConflicts"}, function(response) { + chrome.runtime.sendMessage({ + command: "checkConflicts" + }, function (response) { var isConflicted = []; - if(response.isConflict){ + if (response.isConflict) { var between = response.between; var text = ""; - for(var i = 0; i"+text+""); - } + $("#courseList").prepend("

" + text + ""); + } }); courses = data.savedCourses; - if(courses.length != 0){ + if (courses.length != 0) { $("#empty").hide(); } // build and append the course list element - for(var i = 0; i

"+department + " "+course_nbr+""+" with "+profname+" ("+courses[i].unique+")"+"

"; + var department = courses[i].coursename.substring(0, courses[i].coursename.search(/\d/) - 2); + var course_nbr = courses[i].coursename.substring(courses[i].coursename.search(/\d/), courses[i].coursename.indexOf(" ", courses[i].coursename.search(/\d/))); + var profname = courses[i].profname.substring(0, 1) + courses[i].profname.substring(1).toLowerCase(); + var listhtml = "
  • " + department + " " + course_nbr + "" + " with " + profname + " (" + courses[i].unique + ")" + "

  • "; $("#courseList").append(listhtml); } }); /* prettify the name for the conflict messages*/ -function getSimpleName(coursename, unique){ - var department = coursename.substring(0,coursename.search(/\d/)-2); - var course_nbr = coursename.substring(coursename.search(/\d/),coursename.indexOf(" ",coursename.search(/\d/))); - return department+" "+course_nbr+" ("+unique+")"; +function getSimpleName(coursename, unique) { + var department = coursename.substring(0, coursename.search(/\d/) - 2); + var course_nbr = coursename.substring(coursename.search(/\d/), coursename.indexOf(" ", coursename.search(/\d/))); + return department + " " + course_nbr + " (" + unique + ")"; } /* Update the conflict messages */ -function updateConflicts(){ - chrome.runtime.sendMessage({command: "checkConflicts"}, function(response) { +function updateConflicts() { + chrome.runtime.sendMessage({ + command: "checkConflicts" + }, function (response) { var isConflicted = []; - if(response.isConflict){ + if (response.isConflict) { var between = response.between; var text = ""; - for(var i = 0; i"+text+""); - } + $("#courseList").prepend("

    " + text + ""); + } }); } /* Handle the button clicks */ -$(document).ready(function() { - $("#courseList li").click(function(){ - $(this).find("#listMoreInfo").click(function(){ +$(document).ready(function () { + $("#courseList li").click(function () { + $(this).find("#listMoreInfo").click(function () { window.open(courses[$(this).closest("li").attr("id")].link); }); /* clear the conflict messages, then remove the course and updateConflicts. update the tabs*/ - $(this).find("#listRemove").click(function(){ + $(this).find("#listRemove").click(function () { var thisForm = this; $(thisForm).closest("ul").find("> p").remove(); - chrome.runtime.sendMessage({command: "courseStorage",course: courses[$(thisForm).closest("li").attr("id")], action:"remove"}, function(response) { + 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){ - $("#courseList").fadeOut(300,function(){ + if ($(thisForm).closest("ul").children(':visible').length === 1) { + $("#courseList").fadeOut(300, function () { $("#empty").fadeIn(200); - }); + }); } updateConflicts(); - chrome.tabs.query({}, function(tabs) { - for(var i = 0; i: "+timearr[i].split(",")[0]+" to "+timearr[i].split(",")[1]+"
    "; + var dayarr = Array.from(dtmap.values()); + for (var i = 0; i < dayarr.length; i++) { + output += "" + dayarr[i] + ": " + timearr[i].split(",")[0] + " to " + timearr[i].split(",")[1] + "
    "; } 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