From 024d491e6315e05d2c66701852e6568d3f63e6e5 Mon Sep 17 00:00:00 2001 From: sghsri Date: Tue, 27 Aug 2019 11:01:05 -0500 Subject: [PATCH] open modal when hitting more info from popup or utplanner --- js/background.js | 12 +++++++++++- js/calendar.js | 7 +------ js/courseCatalog.js | 44 ++++++++++++++++++++++++-------------------- js/popup.js | 4 ++-- js/util.js | 7 +++++++ js/utplanner.js | 4 +--- 6 files changed, 46 insertions(+), 32 deletions(-) diff --git a/js/background.js b/js/background.js index 064c5fba..4658eec2 100644 --- a/js/background.js +++ b/js/background.js @@ -1,6 +1,6 @@ var grades; var current_semesters = {}; - +var should_open = false; onStartup(); /* Handle messages and their commands from content and popup scripts*/ @@ -34,9 +34,19 @@ chrome.runtime.onMessage.addListener(function (request, sender, response) { break; case "gradesQuery": executeQuery(request.query, response); + break; case "currentSemesters": response({ semesters: current_semesters}); getCurrentSemesters(); + break; + case "setOpen": + should_open = true; + chrome.tabs.create({ url: request.url}); + break; + case "shouldOpen": + response({open : should_open}); + should_open = false; + break; default: const xhr = new XMLHttpRequest(); const method = request.method ? request.method.toUpperCase() : "GET"; diff --git a/js/calendar.js b/js/calendar.js index 40fa39c3..82f1c451 100644 --- a/js/calendar.js +++ b/js/calendar.js @@ -47,9 +47,6 @@ chrome.storage.sync.get("savedCourses", function (data) { }); }); - - - function displayModal(data) { $("#myModal").fadeIn(calendar_fade_time); $("#colorStrip").css('background-color', data.color); @@ -177,9 +174,7 @@ chrome.runtime.onMessage.addListener( $("#info").click(() => { - setTimeout(() => { - window.open(curr_course.link); - }, button_delay); + openMoreInfoWithOpenModal(curr_course.link); }); diff --git a/js/courseCatalog.js b/js/courseCatalog.js index 9c37e82b..fc4f835f 100644 --- a/js/courseCatalog.js +++ b/js/courseCatalog.js @@ -2,12 +2,8 @@ console.log(`UT Registration Plus is running on this page: ${window.location.hre var curr_course = {} - var semester_code = new URL(window.location.href).pathname.split('/')[4]; var done_loading = true; -updateListConflictHighlighting(); - - var next = $("#next_nav_link"); if (next) { @@ -20,12 +16,6 @@ if (next) { //This extension may be super lit, but you know what's even more lit? //Matthew Tran's twitter and insta: @MATTHEWTRANN and @matthew.trann -$(window).scroll(function () { - if ($(document).height() <= $(window).scrollTop() + $(window).height() + 150) - loadNextPages(); -}); - - if (document.querySelector('#fos_fl')) { let params = (new URL(document.location)).searchParams; let dep = params.get("fos_fl"); @@ -53,9 +43,18 @@ if (!$("#kw_results_table").length) { }); } +if(isIndividualCoursePage()){ + chrome.runtime.sendMessage({ + command: "shouldOpen", + }, function (response) { + if(response.open){ + $("#distButton").click(); + } + }); +} +updateListConflictHighlighting(); -/*Handle the button clicks*/ $("body").on('click', '#distButton', function () { var row = $(this).closest('tr'); $('.modal-content').stop().animate({ @@ -131,7 +130,7 @@ function getCourseInfo(row) { let course_name = ""; let course_row = {} let individual = undefined; - if ($("#textbook_button").length) { + if (isIndividualCoursePage()) { course_name = $("#details h2").text(); course_row = $('table'); individual = document.URL; @@ -562,6 +561,14 @@ function close() { $("#snackbar").attr("class", ""); } +/*Listen for update mssage coming from popup or calendar or other course catalog pages*/ +chrome.runtime.onMessage.addListener( + function (request, sender, sendResponse) { + if (request.command == "updateCourseList") { + updateListConflictHighlighting(0); + } + } +); $(document).keydown(function (e) { /*Close Modal when hit escape*/ @@ -573,11 +580,8 @@ $(document).keydown(function (e) { }); -/*Listen for update mssage coming from popup or calendar or other course catalog pages*/ -chrome.runtime.onMessage.addListener( - function (request, sender, sendResponse) { - if (request.command == "updateCourseList") { - updateListConflictHighlighting(0); - } - } -); +$(window).scroll(function () { + if ($(document).height() <= $(window).scrollTop() + $(window).height() + 150) + loadNextPages(); +}); + diff --git a/js/popup.js b/js/popup.js index 4ce17344..18ddbf4f 100644 --- a/js/popup.js +++ b/js/popup.js @@ -203,7 +203,7 @@ $('#export-class').click(function () { function openCoursePage(sem, unique) { var link = `https://utdirect.utexas.edu/apps/registrar/course_schedule/${sem}/${unique}/`; - window.open(link); + openMoreInfoWithOpenModal(link); } $("#search-class").click(() => { @@ -318,7 +318,7 @@ function subtractHours(curr_course){ function handleMoreInfo(clicked_item, curr_course) { $(clicked_item).find("#listMoreInfo").click(function () { - window.open(curr_course.link); + openMoreInfoWithOpenModal(curr_course.link); }); } diff --git a/js/util.js b/js/util.js index a880eb41..169c027f 100644 --- a/js/util.js +++ b/js/util.js @@ -111,6 +111,9 @@ function seperateCourseNameParts(name) { } } +function isIndividualCoursePage(){ + return $("#textbook_button").length != 0; +} @@ -139,6 +142,10 @@ function setCurrentTabUrl(link) { }); } +function openMoreInfoWithOpenModal(link){ + chrome.runtime.sendMessage({ command: "setOpen", url: link }); +} + function semesterSort(semA, semB) { let semOrder = { diff --git a/js/utplanner.js b/js/utplanner.js index 5e0f1487..422c7e78 100644 --- a/js/utplanner.js +++ b/js/utplanner.js @@ -93,9 +93,7 @@ $("#textbook").click(function () { }); $("#moreInfo").click(function () { - setTimeout(function () { - window.open(curr_course["individual"]); - }, Timing.button_delay); + openMoreInfoWithOpenModal(curr_course["individual"]); });