more refactoring
This commit is contained in:
53
js/Template.js
Normal file
53
js/Template.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
class Template {
|
||||||
|
static mainModal() {
|
||||||
|
return `<div class=modal id=myModal>
|
||||||
|
<div class=modal-content>
|
||||||
|
<span class=close>×</span>
|
||||||
|
<div class=card>
|
||||||
|
<div class=cardcontainer>
|
||||||
|
<h2 class=title id="title">Computer Fluency (C S 302)</h2>
|
||||||
|
<h2 class=profname id="profname">with Bruce Porter</h2>
|
||||||
|
<div id="topbuttons" class=topbuttons>
|
||||||
|
<button class=matbut id="rateMyProf" style="background: #4CAF50;"> RMP </button>
|
||||||
|
<button class=matbut id="eCIS" style="background: #CDDC39;"> eCIS </button>
|
||||||
|
<button class=matbut id="textbook" style="background: #FFC107;"> Textbook </button>
|
||||||
|
<button class=matbut id="Syllabi"> Past Syllabi </button>
|
||||||
|
<button class=matbut id="saveCourse" style="background: #F44336;"> Save Course +</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class=card>
|
||||||
|
<div class=cardcontainer style="">
|
||||||
|
<div class="chartloader">
|
||||||
|
<div class="loader" id='descload'></div>
|
||||||
|
</div>
|
||||||
|
<ul class=description id="description" style="list-style-type:disc"></ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class=card style='text-align:center'>
|
||||||
|
<select id="semesters" style='text-align-last:center;color:#666666;fill:#666666;'>
|
||||||
|
</select>
|
||||||
|
<div class="chartloader">
|
||||||
|
<div class="loader" id='chartload'></div>
|
||||||
|
</div>
|
||||||
|
<div id="chartcontainer" class=cardcontainer>
|
||||||
|
<div id=chart></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`
|
||||||
|
}
|
||||||
|
static catalogLoading() {
|
||||||
|
return `<div style="text-align:center">
|
||||||
|
<div class="loader" id='loader'></div>
|
||||||
|
<br>
|
||||||
|
<h1 id="nextlabel"style="color: #FF9800;display:none;">Loading Courses</h1>
|
||||||
|
<h1 id="retrylabel"style="color: #F44336;display:none;">Failed to Load Courses</h1>
|
||||||
|
<br>
|
||||||
|
<button class=matbut id="retry" style="background: #F44336;display:none;">Retry</button>
|
||||||
|
</div>`
|
||||||
|
}
|
||||||
|
static extensionButton() {
|
||||||
|
return `<td data-th="Plus"><input type="image" class="distButton" id="distButton" width="20" height="20" src='${chrome.extension.getURL('images/disticon.png')}'/></td>`
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,53 +1,58 @@
|
|||||||
var next = $("#next_nav_link");
|
console.log(`UT Registration Plus is running on this page: ${window.location.href}`);
|
||||||
var semesterCode = new URL(window.location.href).pathname.split('/')[4];
|
|
||||||
var doneLoading = true;
|
|
||||||
|
|
||||||
|
|
||||||
var curr_course = {}
|
var curr_course = {}
|
||||||
|
var semesterCode = new URL(window.location.href).pathname.split('/')[4];
|
||||||
|
var doneLoading = true;
|
||||||
|
updateListConflictHighlighting();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var next = $("#next_nav_link");
|
||||||
|
if (next) {
|
||||||
|
chrome.storage.sync.get('loadAll', function (data) {
|
||||||
|
if (data.loadAll)
|
||||||
|
$('[title*="next listing"]').remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//This extension may be super lit, but you know what's even more lit?
|
//This extension may be super lit, but you know what's even more lit?
|
||||||
//Matthew Tran's twitter and insta: @MATTHEWTRANN and @matthew.trann
|
//Matthew Tran's twitter and insta: @MATTHEWTRANN and @matthew.trann
|
||||||
|
|
||||||
console.log('UT Registration Plus is running on this page.');
|
|
||||||
|
|
||||||
$(window).scroll(function () {
|
$(window).scroll(function () {
|
||||||
if ($(document).height() <= $(window).scrollTop() + $(window).height() + 150) {
|
if ($(document).height() <= $(window).scrollTop() + $(window).height() + 150)
|
||||||
loadNextPages();
|
loadNextPages();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (next) {
|
|
||||||
chrome.storage.sync.get('loadAll', function (data) {
|
if (document.querySelector('#fos_fl')) {
|
||||||
if (data.loadAll) {
|
let params = (new URL(document.location)).searchParams;
|
||||||
$('[title*="next listing"]').remove();
|
let dep = params.get("fos_fl");
|
||||||
|
let level = params.get("level");
|
||||||
|
if (dep && level) {
|
||||||
|
if (dep.length == 3 && (level == 'U' || level == 'L' || level == 'G')) {
|
||||||
|
document.querySelector('#fos_fl').value = dep;
|
||||||
|
document.querySelector('#level').value = level;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//make heading and modal
|
//make heading and modal
|
||||||
if (!$("#kw_results_table").length) {
|
if (!$("#kw_results_table").length) {
|
||||||
$("table thead th:last-child").after('<th scope=col>Plus</th>');
|
$("table").after(Template.catalogLoading());
|
||||||
$("table").after(`<div style="text-align:center">
|
$("#container").prepend(Template.mainModal());
|
||||||
<div class="loader" id='loader'></div>
|
|
||||||
<br>
|
|
||||||
<h1 id="nextlabel"style="color: #FF9800;display:none;">Loading Courses</h1>
|
|
||||||
<h1 id="retrylabel"style="color: #F44336;display:none;">Failed to Load Courses</h1>
|
|
||||||
<br>
|
|
||||||
<button class=matbut id="retry" style="background: #F44336;display:none;">Retry</button>
|
|
||||||
</div>`);
|
|
||||||
$("#container").prepend(mainModal());
|
|
||||||
$("#myModal").prepend("<div id='snackbar'>save course popup...</div>");
|
$("#myModal").prepend("<div id='snackbar'>save course popup...</div>");
|
||||||
//go through all the rows in the list
|
|
||||||
|
// now add to the table
|
||||||
|
$("table thead th:last-child").after('<th scope=col>Plus</th>');
|
||||||
$('table').find('tr').each(function () {
|
$('table').find('tr').each(function () {
|
||||||
if (!($(this).find('td').hasClass("course_header")) && $(this).has('th').length == 0) {
|
if (!($(this).find('td').hasClass("course_header")) && $(this).has('th').length == 0) {
|
||||||
//if a course row, then add the extension button
|
$(this).append(Template.extensionButton());
|
||||||
$(this).append(`<td data-th="Plus"><input type="image" class="distButton" id="distButton" style="vertical-align: bottom; display:block;" width="20" height="20" src='${chrome.extension.getURL('images/disticon.png')}'/></td>`);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//update the conflicts
|
|
||||||
update(0);
|
|
||||||
|
|
||||||
/*Handle the button clicks*/
|
/*Handle the button clicks*/
|
||||||
$("body").on('click', '#distButton', function () {
|
$("body").on('click', '#distButton', function () {
|
||||||
var row = $(this).closest('tr');
|
var row = $(this).closest('tr');
|
||||||
@@ -99,27 +104,6 @@ $("#retry").click(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(document).keydown(function (e) {
|
|
||||||
/*Close Modal when hit escape*/
|
|
||||||
if (e.keyCode == 27) {
|
|
||||||
close();
|
|
||||||
} else if (e.keyCode == 13 && $('#myModal').is(':visible')) {
|
|
||||||
saveCourse();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/*Listen for update mssage coming from popup*/
|
|
||||||
chrome.runtime.onMessage.addListener(
|
|
||||||
function (request, sender, sendResponse) {
|
|
||||||
if (request.command == "updateCourseList") {
|
|
||||||
update(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
function sepNameParts(name) {
|
function sepNameParts(name) {
|
||||||
numIndex = name.search(/\d/);
|
numIndex = name.search(/\d/);
|
||||||
department = name.substring(0, numIndex).trim();
|
department = name.substring(0, numIndex).trim();
|
||||||
@@ -234,18 +218,8 @@ function saveCourse() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function toggleSnackbar() {
|
|
||||||
setTimeout(function () {
|
|
||||||
$("#snackbar").attr("class", "show");
|
|
||||||
}, 200);
|
|
||||||
setTimeout(function () {
|
|
||||||
$("#snackbar").attr("class", "");
|
|
||||||
}, 3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the course list to show if the row contains a course that conflicts with the saved course is one of the saved courses */
|
/* 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(start) {
|
function updateListConflictHighlighting(start = 0) {
|
||||||
chrome.storage.sync.get('courseConflictHighlight', function (data) {
|
chrome.storage.sync.get('courseConflictHighlight', function (data) {
|
||||||
let canHighlight = data.courseConflictHighlight;
|
let canHighlight = data.courseConflictHighlight;
|
||||||
$('table').find('tr').each(function (i) {
|
$('table').find('tr').each(function (i) {
|
||||||
@@ -494,11 +468,60 @@ function getDescription(course_info) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadNextPages() {
|
||||||
|
chrome.storage.sync.get('loadAll', function (data) {
|
||||||
|
if (data.loadAll) {
|
||||||
|
let link = next.prop('href');
|
||||||
|
if (doneLoading && next && link) {
|
||||||
|
toggleLoadingPage(true);
|
||||||
|
$.get(link, function (response) {
|
||||||
|
if (response) {
|
||||||
|
var nextpage = $('<div/>').html(response).contents();
|
||||||
|
var current = $('tbody');
|
||||||
|
var oldlength = $('tbody tr').length;
|
||||||
|
var last = current.find('.course_header>h2:last').text();
|
||||||
|
next = nextpage.find("#next_nav_link");
|
||||||
|
toggleLoadingPage(false);
|
||||||
|
var newrows = [];
|
||||||
|
nextpage.find('tbody>tr').each(function () {
|
||||||
|
let hasCourseHead = $(this).find('td').hasClass("course_header");
|
||||||
|
if (!(hasCourseHead && $(this).has('th').length == 0))
|
||||||
|
$(this).append(Template.extensionButton());
|
||||||
|
if (!(hasCourseHead && last == $(this).find('td').text()))
|
||||||
|
newrows.push($(this));
|
||||||
|
});
|
||||||
|
current.append(newrows);
|
||||||
|
updateListConflictHighlighting(oldlength + 1)
|
||||||
|
}
|
||||||
|
}).fail(function () {
|
||||||
|
toggleLoadingPage(false);
|
||||||
|
$("#retrylabel").css('display', 'inline-block');
|
||||||
|
$('#retry').css('display', 'inline-block');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*Listen for update mssage coming from popup*/
|
||||||
|
chrome.runtime.onMessage.addListener(
|
||||||
|
function (request, sender, sendResponse) {
|
||||||
|
if (request.command == "updateCourseList") {
|
||||||
|
updateListConflictHighlighting(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
function toggleLoadingPage(loading) {
|
function toggleLoadingPage(loading) {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
|
doneLoading = false;
|
||||||
$('#loader').css('display', 'inline-block');
|
$('#loader').css('display', 'inline-block');
|
||||||
$("#nextlabel").css('display', 'inline-block');
|
$("#nextlabel").css('display', 'inline-block');
|
||||||
} else {
|
} else {
|
||||||
|
doneLoading = true;
|
||||||
$('#loader').hide();
|
$('#loader').hide();
|
||||||
$("#nextlabel").hide();
|
$("#nextlabel").hide();
|
||||||
}
|
}
|
||||||
@@ -522,45 +545,25 @@ function toggleDescriptionLoading(loading) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadNextPages() {
|
function toggleSnackbar() {
|
||||||
chrome.storage.sync.get('loadAll', function (data) {
|
setTimeout(function () {
|
||||||
if (data.loadAll) {
|
$("#snackbar").attr("class", "show");
|
||||||
let link = next.prop('href');
|
}, 200);
|
||||||
if (doneLoading && next && link) {
|
setTimeout(function () {
|
||||||
toggleLoadingPage(true);
|
$("#snackbar").attr("class", "");
|
||||||
doneLoading = false;
|
}, 3000);
|
||||||
$.get(link, function (response) {
|
|
||||||
if (response) {
|
|
||||||
var nextpage = $('<div/>').html(response).contents();
|
|
||||||
var current = $('tbody');
|
|
||||||
var oldlength = $('tbody tr').length;
|
|
||||||
var last = current.find('.course_header>h2:last').text();
|
|
||||||
next = nextpage.find("#next_nav_link");
|
|
||||||
doneLoading = true;
|
|
||||||
$("#nextlabel").hide();
|
|
||||||
$('#loader').hide();
|
|
||||||
var newrows = [];
|
|
||||||
nextpage.find('tbody>tr').each(function () {
|
|
||||||
let hasCourseHead = $(this).find('td').hasClass("course_header");
|
|
||||||
if (!(hasCourseHead && $(this).has('th').length == 0))
|
|
||||||
$(this).append(extensionButton());
|
|
||||||
if (!(hasCourseHead && last == $(this).find('td').text()))
|
|
||||||
newrows.push($(this));
|
|
||||||
});
|
|
||||||
current.append(newrows);
|
|
||||||
update(oldlength + 1)
|
|
||||||
}
|
|
||||||
}).fail(function () {
|
|
||||||
doneLoading = true;
|
|
||||||
toggleLoadingPage(false);
|
|
||||||
$("#retrylabel").css('display', 'inline-block');
|
|
||||||
$('#retry').css('display', 'inline-block');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$(document).keydown(function (e) {
|
||||||
|
/*Close Modal when hit escape*/
|
||||||
|
if (e.keyCode == 27) {
|
||||||
|
close();
|
||||||
|
} else if (e.keyCode == 13 && $('#myModal').is(':visible')) {
|
||||||
|
saveCourse();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
function allowClosing() {
|
function allowClosing() {
|
||||||
$('.close').click(function () {
|
$('.close').click(function () {
|
||||||
close();
|
close();
|
||||||
|
|||||||
11
js/qol.js
11
js/qol.js
@@ -1,11 +0,0 @@
|
|||||||
if (document.querySelector('#fos_fl')) {
|
|
||||||
let params = (new URL(document.location)).searchParams;
|
|
||||||
let dep = params.get("fos_fl");
|
|
||||||
let level = params.get("level");
|
|
||||||
if (dep && level) {
|
|
||||||
if (dep.length == 3 && (level == 'U' || level == 'L' || level == 'G')) {
|
|
||||||
document.querySelector('#fos_fl').value = dep;
|
|
||||||
document.querySelector('#level').value = level;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
function extensionButton() {
|
|
||||||
return `<td data-th="Plus"><input type="image" class="distButton" id="distButton" width="20" height="20" src='${chrome.extension.getURL('images/disticon.png')}'/></td>`
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function mainModal() {
|
|
||||||
return `<div class=modal id=myModal>
|
|
||||||
<div class=modal-content>
|
|
||||||
<span class=close>×</span>
|
|
||||||
<div class=card>
|
|
||||||
<div class=cardcontainer>
|
|
||||||
<h2 class=title id="title">Computer Fluency (C S 302)</h2>
|
|
||||||
<h2 class=profname id="profname">with Bruce Porter</h2>
|
|
||||||
<div id="topbuttons" class=topbuttons>
|
|
||||||
<button class=matbut id="rateMyProf" style="background: #4CAF50;"> RMP </button>
|
|
||||||
<button class=matbut id="eCIS" style="background: #CDDC39;"> eCIS </button>
|
|
||||||
<button class=matbut id="textbook" style="background: #FFC107;"> Textbook </button>
|
|
||||||
<button class=matbut id="Syllabi"> Past Syllabi </button>
|
|
||||||
<button class=matbut id="saveCourse" style="background: #F44336;"> Save Course +</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class=card>
|
|
||||||
<div class=cardcontainer style="">
|
|
||||||
<div class="chartloader">
|
|
||||||
<div class="loader" id='descload'></div>
|
|
||||||
</div>
|
|
||||||
<ul class=description id="description" style="list-style-type:disc"></ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class=card style='text-align:center'>
|
|
||||||
<select id="semesters" style='text-align-last:center;color:#666666;fill:#666666;'>
|
|
||||||
</select>
|
|
||||||
<div class="chartloader">
|
|
||||||
<div class="loader" id='chartload'></div>
|
|
||||||
</div>
|
|
||||||
<div id="chartcontainer" class=cardcontainer>
|
|
||||||
<div id=chart></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>`
|
|
||||||
}
|
|
||||||
@@ -2,12 +2,12 @@ if ($('html').hasClass('gr__utexas_collegescheduler_com')) {
|
|||||||
$.initialize("table.section-detail-grid", function () {
|
$.initialize("table.section-detail-grid", function () {
|
||||||
$(this).find('thead>tr').append('<th> Plus</th')
|
$(this).find('thead>tr').append('<th> Plus</th')
|
||||||
$(this).find('tbody>tr').each(function () {
|
$(this).find('tbody>tr').each(function () {
|
||||||
$(this).append(extensionButton());
|
$(this).append(Template.extensionButton());
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
curr_course = {}
|
curr_course = {}
|
||||||
$("body").prepend(mainModal());
|
$("body").prepend(Template.mainModal());
|
||||||
|
|
||||||
$("body").on('click', '#distButton', function () {
|
$("body").on('click', '#distButton', function () {
|
||||||
var row = $(this).closest('tr');
|
var row = $(this).closest('tr');
|
||||||
|
|||||||
@@ -17,13 +17,13 @@
|
|||||||
"content_scripts": [{
|
"content_scripts": [{
|
||||||
"css": ["css/styles.css"],
|
"css": ["css/styles.css"],
|
||||||
"js": ["js/lib/moment.min.js", "js/lib/highcharts.js", "js/lib/jquery-3.3.1.min.js", "js/lib/jquery.initialize.min.js", "js/config.js", "js/util.js",
|
"js": ["js/lib/moment.min.js", "js/lib/highcharts.js", "js/lib/jquery-3.3.1.min.js", "js/lib/jquery.initialize.min.js", "js/config.js", "js/util.js",
|
||||||
"js/qol.js", "js/templates.js", "js/courseCatalog.js"
|
"js/Template.js", "js/courseCatalog.js"
|
||||||
],
|
],
|
||||||
"matches": ["https://utdirect.utexas.edu/apps/registrar/course_schedule/*"]
|
"matches": ["https://utdirect.utexas.edu/apps/registrar/course_schedule/*"]
|
||||||
}, {
|
}, {
|
||||||
"css": ["css/styles.css"],
|
"css": ["css/styles.css"],
|
||||||
"js": ["js/lib/moment.min.js", "js/lib/highcharts.js", "js/lib/jquery-3.3.1.min.js", "js/lib/jquery.initialize.min.js", "js/config.js", "js/util.js",
|
"js": ["js/lib/moment.min.js", "js/lib/highcharts.js", "js/lib/jquery-3.3.1.min.js", "js/lib/jquery.initialize.min.js", "js/config.js", "js/util.js",
|
||||||
"js/templates.js", "js/utPlanner.js"
|
"js/Template.js", "js/utPlanner.js"
|
||||||
],
|
],
|
||||||
"matches": ["https://utexas.collegescheduler.com/*"]
|
"matches": ["https://utexas.collegescheduler.com/*"]
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
Reference in New Issue
Block a user