diff --git a/calendar.html b/calendar.html index 7b767804..f65d12cd 100644 --- a/calendar.html +++ b/calendar.html @@ -1,5 +1,5 @@ - +
diff --git a/js/background.js b/js/background.js index 2aa507f1..b30850f8 100644 --- a/js/background.js +++ b/js/background.js @@ -1,8 +1,10 @@ -var grades; +console.log(`UT Registration Plus background page: ${window.location.href}`); +var grades; // caching the grades database in memory for faster queries var current_semesters = {}; var departments = []; -var should_open = false; +var should_open = false; // toggled flag for automatically opening popup on new pages when 'more info' hit +// these are the default options that the extension currently supports const default_options = { loadAll: true, courseConflictHighlight: true, @@ -11,6 +13,13 @@ const default_options = { onStartup(); +function onStartup() { + updateBadge(true); + loadDataBase(); + getCurrentSemesters(); + getCurrentDepartments(); +} + /* Handle messages and their commands from content and popup scripts*/ chrome.runtime.onMessage.addListener(function (request, sender, response) { switch (request.command) { @@ -89,38 +98,27 @@ chrome.runtime.onInstalled.addListener(function (details) { setDefaultOptions(); chrome.storage.sync.get("savedCourses", function (data) { if (!data.savedCourses) { - chrome.storage.sync.set( - { - savedCourses: new Array(), - }, - function () { - console.log("initial course list"); - } - ); + chrome.storage.sync.set({ + savedCourses: [], + }); } }); } else if (details.reason == "update") { - console.log("updated"); + // if there's been an update, call setDefaultOptions in case their settings have gotten wiped setDefaultOptions(); + console.log("updated"); } }); chrome.storage.onChanged.addListener(function (changes) { for (key in changes) { - console.log(changes); if (key === "savedCourses") { - updateBadge(false, changes.savedCourses.newValue); + updateBadge(false, changes.savedCourses.newValue); // update the extension popup badge whenever the savedCourses have been changed } } }); -function onStartup() { - updateBadge(true); - loadDataBase(); - getCurrentSemesters(); - getCurrentDepartments(); -} - +// get the value of an option if it exists function getOptionsValue(key, sendResponse) { chrome.storage.sync.get("options", function (data) { if (!data.options) { @@ -133,10 +131,12 @@ function getOptionsValue(key, sendResponse) { }); } +// set the value of an option if it exists function setOptionsValue(key, value, sendResponse) { chrome.storage.sync.get("options", function (data) { let new_options = data.options; if (!data.options) { + // if there are no options set, set the defaults setDefaultOptions(); new_options = default_options; } @@ -146,8 +146,6 @@ function setOptionsValue(key, value, sendResponse) { options: new_options, }, function () { - console.log(key); - console.log(new_options); sendResponse({ value: new_options[key], }); @@ -156,6 +154,7 @@ function setOptionsValue(key, value, sendResponse) { }); } +// set the default options if the options haven't been set before function setDefaultOptions() { chrome.storage.sync.get("options", function (data) { if (!data.options) { @@ -164,20 +163,21 @@ function setDefaultOptions() { options: default_options, }, function () { - console.log("default options:"); - console.log(default_options); + console.log("default options:", default_options); } ); } }); } +// scrape the registrar schedules page for caching the current active semesters function getCurrentSemesters() { $.get("https://registrar.utexas.edu/schedules", function (response) { if (response) { htmlToNode(response) .find(".callout2>ul>li>a") .each(function (i) { + // only show as many semesters as we want to display if (i < Popup.num_semesters) { let sem_name = $(this).text().trim(); if (sem_name != "Course Schedule Archive") { @@ -203,14 +203,14 @@ function getCurrentSemesters() { }); } +// use the utexas review api for getting the list of departments function getCurrentDepartments() { $.get("https://www.utexasreview.com/api/get_major", function (response) { if (response) { - console.log("getCurrentDepartments -> response", response); let { majors } = response; let indices = Object.keys(majors); let new_departments = []; - for(let i = 0; iSriram Hariharan (2018)
-