$(function () { const materialColors = ['#4CAF50', '#CDDC39', '#FFC107', '#2196F3', '#F57C00', '#9C27B0', '#FF5722', '#673AB7', '#FF5252', '#E91E63', '#009688', '#00BCD4', '#4E342E', '#424242', '#9E9E9E' ]; const days = new Map([ ["M", "Monday"], ["T", "Tuesday"], ["W", "Wednesday"], ["TH", "Thursday"], ["F", "Friday"] ]); const fadetime = 150; const butdelay = 75; $("#calendar").prepend('
${dayarr[i]}: ${timearr[i].split(",")[0]} to ${timearr[i].split(",")[1]}${place}
`; } return output; } // When the user clicks on (x), close the modal $(".close").click(() => { $("#myModal").fadeOut(fadetime); }); $("#info").click(() => { setTimeout(() => { 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) { $("#myModal").fadeOut(fadetime); } $("#snackbar").attr("class", ""); }); // When the user clicks anywhere outside of the modal, close it window.onclick = (event) => { var modal = document.getElementById("myModal"); if (event.target == modal) { $("#myModal").fadeOut(fadetime); } } //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; } // Iterate through each saved course and add to 'event' function setAllEvents(savedCourses) { colorCounter = 0; classSchedules = []; for (let i = 0; i < savedCourses.length; i++) { for (let j = 0; j < savedCourses[i].datetimearr.length; j++) { let session = savedCourses[i].datetimearr[j]; // One single session for a class setEventForSection(session, colorCounter, i); } colorCounter++; } } //create the event object for every section function setEventForSection(session, colorCounter, i) { var fullday = days.get(session[0]); var classInfo = savedCourses[i]; var department = classInfo.coursename.substring(0, classInfo.coursename.search(/\d/) - 2); var course_nbr = classInfo.coursename.substring(classInfo.coursename.search(/\d/), classInfo.coursename.indexOf(" ", classInfo.coursename.search(/\d/))); var uncapProf = prettifyName(classInfo.profname); if (uncapProf == "") { uncapProf = "Undecided"; } classSchedules.push({ title: `${department}-${course_nbr} with ${uncapProf}`, start: moment().format("YYYY-MM-") + moment() .day(fullday) ._d.toString() .split(" ")[2] + "T" + session[1][0] + ":00", end: moment().format("YYYY-MM-") + moment() .day(fullday) ._d.toString() .split(" ")[2] + "T" + session[1][1] + ":00", color: materialColors[colorCounter], index: i, allday: false }); } chrome.runtime.onMessage.addListener( function (request, sender, sendResponse) { if (request.command == "updateCourseList" || request.command == "courseAdded") { 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); }); } /* Format the Professor Name */ function prettifyName(profname) { return profname.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); } });