From 908241fd67f3cdf420aeb02dd774ba5fadf2dcb1 Mon Sep 17 00:00:00 2001 From: sghsri Date: Sun, 23 Aug 2020 23:11:01 -0500 Subject: [PATCH] Added github contributors to options page --- css/options.css | 81 ++++++++++++++++ js/Template.js | 72 +++++++------- js/background.js | 248 ++++++++++++++++++++++++----------------------- js/config.js | 80 ++++++++++----- js/options.js | 70 ++++++++----- options.html | 43 ++++---- 6 files changed, 362 insertions(+), 232 deletions(-) create mode 100644 css/options.css diff --git a/css/options.css b/css/options.css new file mode 100644 index 00000000..95dd4bc7 --- /dev/null +++ b/css/options.css @@ -0,0 +1,81 @@ +.version { + padding: 0px 5px 5px 0px; + text-align: right; +} + +.creator-tag { + margin: 10px 5px 5px 0px; + text-align: center; +} + +.options-card { + width: 400px; + margin-left: auto; + margin-right: auto; + height: auto; + padding-bottom: 5px; +} + +#version-container { + margin-left: auto; + margin-right: auto; + width: 400px; +} + +.options-header { + padding: 16px 16px 0px 16px; + font-size: 20px; +} + +#contributors_container { + text-align: center; + margin-top: 30; + padding: 5px 20px 20px 20px; + width: auto; + margin-right: 20%; + margin-left: 20%; + margin-top: 20px; +} + +#contributor-list { + max-width: 1200px; + margin: 0 auto; + display: grid; + grid-gap: 1rem; + grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); +} + +.contributor-card { + cursor: pointer; + padding: 5px; + max-width: 1200px; + margin: 0 auto; + text-align: center; + display: grid; + grid-gap: 1rem; +} + +.contributor-card img { + width: 200px; + height: 200px; +} + +.contributor-name { + font-weight: bold; + margin: 0; +} + +.contributor-username { + margin: 0 0 5px 0; + font-style: italic; +} + +.contributor-title { + margin-bottom: 0; + font-size: 15px; +} + +.open-source-tag { + padding: 10px; + font-size: 16px; +} diff --git a/js/Template.js b/js/Template.js index 8467cd9d..ad9b2da7 100644 --- a/js/Template.js +++ b/js/Template.js @@ -1,4 +1,4 @@ -class Template{} +class Template {} Template.Main = class { static modal() { @@ -37,12 +37,12 @@ Template.Main = class { - ` + `; } static extension_button() { - return `` + return ``; } -} +}; Template.Catalog = class { static loading() { return `
@@ -52,11 +52,11 @@ Template.Catalog = class {

Failed to Load Courses


-
` + `; } -} +}; Template.UTPlanner = class { - static modal(){ + static modal() { return ` - ` + `; } -} +}; Template.Calendar = class { static line(line) { - let { - days, - start_time, - end_time, - location_link, - location_full - } = line; + let { days, start_time, end_time, location_link, location_full } = line; return `

${days}: ${start_time} to ${end_time} ${location_full} -

` +

`; } static modal() { return ` - ` + `; } -} +}; Template.Popup = class { static list_item(i, list_tile_color, unique, department, number, profname, list_sub_color, line) { return `
  • @@ -150,26 +144,20 @@ Template.Popup = class { } static conflict_message(conflict_message) { - return `

    ${conflict_message}` + return `

    ${conflict_message}`; } static line(line) { - let { - days, - start_time, - end_time, - location_link, - location_full - } = line; + let { days, start_time, end_time, location_link, location_full } = line; return `${days}: ${start_time} to ${end_time} ${location_full} -
    ` +
    `; } -} +}; Template.Import = class { static import_button() { return `
    `; @@ -179,16 +167,15 @@ Template.Import = class { return `
    `; } - static store_waitlist_message(){ - return `

    ` + static store_waitlist_message() { + return `

    `; } - -} +}; Template.Options = class { - static options_row(key, enabled){ - let button_text = enabled ? "Turn Off" : "Turn On"; - let button_color = enabled ? Colors.closed : Colors.open; + static options_row(key, enabled) { + let button_text = enabled ? "Turn Off" : "Turn On"; + let button_color = enabled ? Colors.closed : Colors.open; let label_text = capitalizeString(key.replace(/([A-Z]+)*([A-Z][a-z])/g, "$1 $2")); return `

    ${label_text} @@ -196,7 +183,14 @@ Template.Options = class { -
    ` - +
    `; } -} + + static contributor_card(username, name, image_url, profile_url) { + return `
    + + ${name ? `

    ${name}

    ` : ""} +

    ${username}

    +
    `; + } +}; diff --git a/js/background.js b/js/background.js index f534ec19..065f12d8 100644 --- a/js/background.js +++ b/js/background.js @@ -4,10 +4,10 @@ var departments = []; var should_open = false; const default_options = { - "loadAll": true, - "courseConflictHighlight": true, - "storeWaitlist": true, -} + loadAll: true, + courseConflictHighlight: true, + storeWaitlist: true, +}; onStartup(); @@ -44,18 +44,18 @@ chrome.runtime.onMessage.addListener(function (request, sender, response) { executeQuery(request.query, response); break; case "currentSemesters": - response({ semesters: current_semesters}); + response({ semesters: current_semesters }); getCurrentSemesters(); break; case "currentDepartments": - response({departments: departments}); + response({ departments: departments }); break; case "setOpen": should_open = true; - chrome.tabs.create({ url: request.url}); + chrome.tabs.create({ url: request.url }); break; case "shouldOpen": - response({open : should_open}); + response({ open: should_open }); should_open = false; break; case "getOptionsValue": @@ -72,7 +72,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, response) { xhr.onload = () => { console.log(xhr.responseUrl); response(xhr.responseText); - } + }; xhr.onerror = () => response(xhr.statusText); if (method == "POST") { xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); @@ -87,13 +87,16 @@ chrome.runtime.onMessage.addListener(function (request, sender, response) { chrome.runtime.onInstalled.addListener(function (details) { if (details.reason == "install") { setDefaultOptions(); - chrome.storage.sync.get('savedCourses', function (data) { + 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: new Array(), + }, + function () { + console.log("initial course list"); + } + ); } }); } else if (details.reason == "update") { @@ -102,163 +105,169 @@ chrome.runtime.onInstalled.addListener(function (details) { } }); - chrome.storage.onChanged.addListener(function (changes) { for (key in changes) { console.log(changes); - if (key === 'savedCourses') { + if (key === "savedCourses") { updateBadge(false, changes.savedCourses.newValue); } } }); -function onStartup(){ +function onStartup() { updateBadge(true); - loadDataBase() + loadDataBase(); getCurrentSemesters(); getCurrentDepartments(); } -function getOptionsValue(key, sendResponse){ - chrome.storage.sync.get('options', function (data) { +function getOptionsValue(key, sendResponse) { + chrome.storage.sync.get("options", function (data) { if (!data.options) { setDefaultOptions(); } else { sendResponse({ - 'value': data.options[key] + value: data.options[key], }); } }); } -function setOptionsValue(key, value, sendResponse){ - chrome.storage.sync.get('options', function (data) { +function setOptionsValue(key, value, sendResponse) { + chrome.storage.sync.get("options", function (data) { let new_options = data.options; if (!data.options) { setDefaultOptions(); new_options = default_options; } new_options[key] = value; - chrome.storage.sync.set({ - options: new_options - }, function () { - console.log(key); - console.log(new_options); - sendResponse({ - 'value': new_options[key] - }); - }); + chrome.storage.sync.set( + { + options: new_options, + }, + function () { + console.log(key); + console.log(new_options); + sendResponse({ + value: new_options[key], + }); + } + ); }); } -function setDefaultOptions(){ - chrome.storage.sync.get('options', function (data) { +function setDefaultOptions() { + chrome.storage.sync.get("options", function (data) { if (!data.options) { - chrome.storage.sync.set({ - options: default_options - }, function () { - console.log('default options:'); - console.log(default_options); - }); - } - }); -} - -function getCurrentSemesters(){ - $.get('https://registrar.utexas.edu/schedules', function (response) { - if (response) { - htmlToNode(response).find('.callout2>ul>li>a').each(function (i) { - if (i < Popup.num_semesters) { - let sem_name = $(this).text().trim(); - if (sem_name != "Course Schedule Archive") { - // $("#semesters").append(``); - current_semesters[sem_name] = "code"; - $.get($(this).attr('href'), function (response) { - if (response) { - let response_node = htmlToNode(response); - let name = response_node.find(".page-title").text().substring(17).trim(); - response_node.find('.gobutton>a').each(function () { - let link = $(this).attr('href'); - var sem_num = link.substring(link.lastIndexOf('/') + 1).trim(); - if(current_semesters[name] != sem_num){ - current_semesters[name] = sem_num; - } - }); - } - }); - } + chrome.storage.sync.set( + { + options: default_options, + }, + function () { + console.log("default options:"); + console.log(default_options); } - }); + ); } }); } - -function getCurrentDepartments(){ - $.get('https://catalog.utexas.edu/undergraduate/appendix-b/', function(response){ - if(response){; - departments = []; - htmlToNode(response).find('.column1').each(function(i){ - if(i > 1){ - let abv = $(this).text(); - departments.push(abv); +function getCurrentSemesters() { + $.get("https://registrar.utexas.edu/schedules", function (response) { + if (response) { + htmlToNode(response) + .find(".callout2>ul>li>a") + .each(function (i) { + if (i < Popup.num_semesters) { + let sem_name = $(this).text().trim(); + if (sem_name != "Course Schedule Archive") { + // $("#semesters").append(``); + current_semesters[sem_name] = "code"; + $.get($(this).attr("href"), function (response) { + if (response) { + let response_node = htmlToNode(response); + let name = response_node.find(".page-title").text().substring(17).trim(); + response_node.find(".gobutton>a").each(function () { + let link = $(this).attr("href"); + var sem_num = link.substring(link.lastIndexOf("/") + 1).trim(); + if (current_semesters[name] != sem_num) { + current_semesters[name] = sem_num; + } + }); + } + }); + } + } + }); } - }); - } - }); + }); +} + +function getCurrentDepartments() { + $.get("https://catalog.utexas.edu/undergraduate/appendix-b/", function (response) { + if (response) { + departments = []; + htmlToNode(response) + .find(".column1") + .each(function (i) { + if (i > 1) { + let abv = $(this).text(); + departments.push(abv); + } + }); + } + }); } function updateBadge(first, new_changes) { if (new_changes) { updateBadgeText(first, new_changes); } else { - chrome.storage.sync.get('savedCourses', function (data) { + chrome.storage.sync.get("savedCourses", function (data) { let courses = data.savedCourses; updateBadgeText(first, courses); }); } } - function updateBadgeText(first, courses) { let badge_text = courses.length > 0 ? `${courses.length}` : ""; let flash_time = !first ? 200 : 0; chrome.browserAction.setBadgeText({ - text: badge_text + text: badge_text, }); if (!first) { chrome.browserAction.setBadgeBackgroundColor({ - color: Colors.badge_flash + color: Colors.badge_flash, }); } setTimeout(function () { chrome.browserAction.setBadgeBackgroundColor({ - color: Colors.badge_default + color: Colors.badge_default, }); }, flash_time); } /* Find all the conflicts in the courses and send them out/ if there is even a conflict*/ function checkConflicts(sendResponse) { - chrome.storage.sync.get('savedCourses', function (data) { + chrome.storage.sync.get("savedCourses", function (data) { var conflicts = []; var courses = data.savedCourses; for (let i = 0; i < courses.length; i++) { for (let j = i + 1; j < courses.length; j++) { let course_a = courses[i]; let course_b = courses[j]; - if (isConflict(course_a.datetimearr, course_b.datetimearr)) - conflicts.push([course_a, course_b]); + if (isConflict(course_a.datetimearr, course_b.datetimearr)) conflicts.push([course_a, course_b]); } } if (conflicts.length == 0) { sendResponse({ - isConflict: false + isConflict: false, }); } else { sendResponse({ isConflict: true, - between: conflicts + between: conflicts, }); } }); @@ -266,7 +275,7 @@ function checkConflicts(sendResponse) { /* Find if the course at unique and with currdatearr is contained in the saved courses and if it conflicts with any other courses*/ function isSingleConflict(currdatearr, unique, sendResponse) { - chrome.storage.sync.get('savedCourses', function (data) { + chrome.storage.sync.get("savedCourses", function (data) { var courses = data.savedCourses; var conflict_list = []; var conflict = false; @@ -284,14 +293,11 @@ function isSingleConflict(currdatearr, unique, sendResponse) { sendResponse({ isConflict: conflict, alreadyContains: contains, - conflictList: conflict_list + conflictList: conflict_list, }); }); } - - - /* Check if conflict between two date-time-arrs*/ function isConflict(adtarr, bdtarr) { for (var i = 0; i < adtarr.length; i++) { @@ -312,25 +318,25 @@ function isConflict(adtarr, bdtarr) { /* Add the requested course to the storage*/ function add(request, sender, sendResponse) { - chrome.storage.sync.get('savedCourses', function (data) { + chrome.storage.sync.get("savedCourses", function (data) { var courses = data.savedCourses; if (!contains(courses, request.course.unique)) { - courses.push(request.course) + courses.push(request.course); console.log(courses); chrome.storage.sync.set({ - savedCourses: courses + savedCourses: courses, }); } sendResponse({ done: "Added: (" + request.course.unique + ") " + request.course.coursename, label: "Remove Course -", - value: "remove" + value: "remove", }); }); } /* Find and Remove the requested course from the storage*/ function remove(request, sender, sendResponse) { - chrome.storage.sync.get('savedCourses', function (data) { + chrome.storage.sync.get("savedCourses", function (data) { var courses = data.savedCourses; console.log(courses); var index = 0; @@ -339,22 +345,22 @@ function remove(request, sender, sendResponse) { } courses.splice(index, 1); chrome.storage.sync.set({ - savedCourses: courses + savedCourses: courses, }); sendResponse({ done: "Removed: (" + request.course.unique + ") " + request.course.coursename, label: "Add Course +", - value: "add" + value: "add", }); }); } /* Find if the unique is already contained within the storage*/ function alreadyContains(unique, sendResponse) { - chrome.storage.sync.get('savedCourses', function (data) { + chrome.storage.sync.get("savedCourses", function (data) { var courses = data.savedCourses; sendResponse({ - alreadyContains: contains(courses, unique) + alreadyContains: contains(courses, unique), }); }); } @@ -371,14 +377,14 @@ function contains(courses, unique) { } function isSameCourse(course, unique) { - return course.unique == unique + return course.unique == unique; } function updateTabs() { chrome.tabs.query({}, function (tabs) { for (var i = 0; i < tabs.length; i++) { chrome.tabs.sendMessage(tabs[i].id, { - command: "updateCourseList" + command: "updateCourseList", }); } }); @@ -388,9 +394,8 @@ const UPDATE_INTERVAL = 1000 * 60 * 16; setInterval(updateStatus, UPDATE_INTERVAL); // updateStatus(); - function updateStatus(sendResponse) { - chrome.storage.sync.get('savedCourses', function (data) { + chrome.storage.sync.get("savedCourses", function (data) { var courses = data.savedCourses; var no_change = true; for (let i = 0; i < courses.length; i++) { @@ -403,37 +408,34 @@ function updateStatus(sendResponse) { success: function (result) { if (result) { console.log(result); - var object = $('
    ').html(result).contents(); + var object = $("
    ").html(result).contents(); let new_status = object.find('[data-th="Status"]').text(); let register_link = object.find('td[data-th="Add"] a'); - if (register_link) - register_link = register_link.attr('href'); - var haschanged = (new_status == old_status && register_link == old_link); - if (!haschanged) - console.log(c.unique + ' updated from ' + old_status + " to " + new_status + " and " + old_link + " to " + register_link); + if (register_link) register_link = register_link.attr("href"); + var haschanged = new_status == old_status && register_link == old_link; + if (!haschanged) console.log(c.unique + " updated from " + old_status + " to " + new_status + " and " + old_link + " to " + register_link); no_change &= haschanged; c.registerlink = register_link; c.status = new_status; } - } + }, }); } catch (e) { console.log(e); - console.log('Not logged into UT Coursebook. Could not update class statuses.'); + console.log("Not logged into UT Coursebook. Could not update class statuses."); } } if (!no_change) { chrome.storage.sync.set({ - savedCourses: courses + savedCourses: courses, }); - console.log('updated status'); + console.log("updated status"); } }); } - function executeQuery(query, sendResponse) { - console.log(grades) + console.log(grades); var res = grades.exec(query)[0]; sendResponse({ data: res, @@ -443,7 +445,7 @@ function executeQuery(query, sendResponse) { /* Load the database*/ function loadDataBase() { sql = window.SQL; - loadBinaryFile('grades.db', function (data) { + loadBinaryFile("grades.db", function (data) { var sqldb = new SQL.Database(data); grades = sqldb; }); @@ -460,4 +462,4 @@ function loadBinaryFile(path, success) { success(arr.join("")); }; xhr.send(); -}; +} diff --git a/js/config.js b/js/config.js index 5ad8a167..b47695ae 100644 --- a/js/config.js +++ b/js/config.js @@ -1,27 +1,36 @@ -class Timing{} +class Timing {} Timing.fade_time = 100; Timing.calendar_fade_time = 100; Timing.button_delay = 75; - -class Colors{} -Colors.material_colors = ['#4CAF50', '#CDDC39', - '#FFC107', '#2196F3', '#F57C00', '#9C27B0', '#FF5722', '#673AB7', - '#FF5252', '#E91E63', '#009688', '#00BCD4', - '#4E342E', '#424242', '#9E9E9E' +class Colors {} +Colors.material_colors = [ + "#4CAF50", + "#CDDC39", + "#FFC107", + "#2196F3", + "#F57C00", + "#9C27B0", + "#FF5722", + "#673AB7", + "#FF5252", + "#E91E63", + "#009688", + "#00BCD4", + "#4E342E", + "#424242", + "#9E9E9E", ]; Colors.open = "#4CAF50"; Colors.waitlisted = "#FF9800"; Colors.closed = "#FF5722"; Colors.no_status = "#607D8B"; - Colors.open_light = "#C8E6C9"; Colors.waitlisted_light = "#FFE0B2"; Colors.closed_light = "#FFCCBC"; Colors.no_status_light = "#CFD8DC"; - Colors.highlight_conflict = "#F44336"; Colors.highlight_default = "#333333"; Colors.highlight_saved = "#4CAF50"; @@ -29,31 +38,50 @@ Colors.highlight_saved = "#4CAF50"; Colors.badge_flash = "#FF5722"; Colors.badge_default = "#bf5700"; - -class Export{} +class Export {} Export.png_options = { - foreignObjectRendering: true, - logging: true, - removeContainer: true, - async: true, -} + foreignObjectRendering: true, + logging: true, + removeContainer: true, + async: true, +}; class Popup {} Popup.num_semesters = 2; -class Text{} -Text.emptyText = function(){ - let arr = ["Doesn't Look Like Anything To Me.", "You Can't Fail Classes You're Not In.", "Pro-Tip: Don't Take O-Chem.", - "No Work Happens On PCL 5th Floor.", "Sophomore But Freshman By Credit.", "Pain is temporary, GPA is forever.", - "You've Yee'd Your Last Haw.", "lol everything is already waitlisted.", "At Least You're Not At A&M.", - `It's ${moment().format("h:mm")} and OU Still Sucks.`, 'TeXAs iS BaCK GuYZ', "'Academically Challenged'", - 'Does McCombs teach Parseltongue?', 'Lets make Daddy Fenves proud.', 'Feel bad if you say Wampus.', 'No Cruce Enfrente Del Bus.', - 'Midterm 1 has been Unmuted', 'Omae Wa Mou Shindeiru...', 'Bevo Bucks are the new Bitcoin', 'Subway Robber > Machete Guy' - ] +class Text {} +Text.emptyText = function () { + let arr = [ + "Doesn't Look Like Anything To Me.", + "You Can't Fail Classes You're Not In.", + "Pro-Tip: Don't Take O-Chem.", + "Jendy's Fofofo™", + "Fine Dining at Jester City Limits", + "Rec Sports is full and it's only 2pm.", + "Hope Domino is doing well rn 🥺", + "The year is 2055 and Welch still isn't finished.", + "Wear a Mask.", + "Motivation dropping faster than ur GPA", + "No Work Happens On PCL 5th Floor.", + "Sophomore But Freshman By Credit.", + "Pain is temporary, GPA is forever.", + "You've Yee'd Your Last Haw.", + "lol everything is already waitlisted.", + "At Least You're Not At A&M.", + `It's ${moment().format("h:mm")} and OU Still Sucks.`, + "TeXAs iS BaCK GuYZ", + "'Academically Challenged'", + "Does McCombs teach Parseltongue?", + "Feel bad if you say Wampus.", + "No Cruce Enfrente Del Bus.", + "Midterm 1 has been Unmuted", + "Omae Wa Mou Shindeiru...", + "Bevo Bucks are the new Bitcoin", + ]; let index = Math.floor(Math.random() * arr.length); return arr[index]; -} +}; Text.button_text_default = "Import to UT Reg +"; Text.waitlist_button_text_default = "Import Waitlists to UT Reg +"; Text.button_success = "Courses Saved!"; diff --git a/js/options.js b/js/options.js index 3092dcef..7422de70 100644 --- a/js/options.js +++ b/js/options.js @@ -1,37 +1,55 @@ var manifestData = chrome.runtime.getManifest(); $("#version").text(manifestData.version); -chrome.storage.sync.get('options', function(data){ - if(data.options){ - console.log(data.options); - Object.keys(data.options).forEach(key => { - let enabled = data.options[key]; - $('#options_container').append(Template.Options.options_row(key, enabled)); - }); - } +chrome.storage.sync.get("options", function (data) { + if (data.options) { + console.log(data.options); + Object.keys(data.options).forEach(key => { + let enabled = data.options[key]; + $("#options_container").append(Template.Options.options_row(key, enabled)); + }); + } }); -$("body").on("click","button",function(){ - let key = $(this).attr('id'); - let old_status = $(this).val() === 'true'; - let new_status = !old_status; - chrome.runtime.sendMessage({ - command: "setOptionsValue", - key: key, - value: new_status - }, function (response) { - console.log(response.value); - toggle(key, response.value) - updateAllTabsCourseList(); - }); +$("body").on("click", "button", function () { + let key = $(this).attr("id"); + let old_status = $(this).val() === "true"; + let new_status = !old_status; + chrome.runtime.sendMessage( + { + command: "setOptionsValue", + key: key, + value: new_status, + }, + function (response) { + console.log(response.value); + toggle(key, response.value); + updateAllTabsCourseList(); + } + ); }); +$.get("https://api.github.com/repos/sghsri/UT-Registration-Plus/stats/contributors", data => { + data = data.sort((a, b) => b.total - a.total); + console.log("data", data); + for (var contributorData of data) { + $.get(`https://api.github.com/users/${contributorData.author.login}`, userData => { + let fullData = { ...contributorData, ...userData }; + let { login, avatar_url, html_url, name } = fullData; + $("#contributor-list").append(Template.Options.contributor_card(login, name, avatar_url, html_url)); + }); + } +}); +$("body").on("click", ".contributor-card", function () { + console.log("hello world"); + window.open($(this).data("url"), "_blank"); +}); function toggle(key, value) { - let button_text = value ? "Turn Off": "Turn On"; - let button_color = value ? Colors.closed : Colors.open ; - $(`#${key}`).text(button_text); - $(`#${key}`).css("background", button_color); - $(`#${key}`).val(value); + let button_text = value ? "Turn Off" : "Turn On"; + let button_color = value ? Colors.closed : Colors.open; + $(`#${key}`).text(button_text); + $(`#${key}`).css("background", button_color); + $(`#${key}`).val(value); } diff --git a/options.html b/options.html index 1cfce2ae..f73c73e0 100644 --- a/options.html +++ b/options.html @@ -1,23 +1,30 @@ + + + + + - - - - - - -