dynamic options, now store options as object rather than individually, waitlist scraping base
This commit is contained in:
@@ -178,4 +178,25 @@ Template.Import = class {
|
|||||||
static waitlist_import_button() {
|
static waitlist_import_button() {
|
||||||
return `<button class='material-button' id='import_waitlist' style='margin:0px'>${Text.waitlist_button_text_default}</button><br>`;
|
return `<button class='material-button' id='import_waitlist' style='margin:0px'>${Text.waitlist_button_text_default}</button><br>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static store_waitlist_message(){
|
||||||
|
return `<h1 id="nextlabel"style="color: #FF9800;display:none;"></h1>`
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Template.Options = class {
|
||||||
|
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 `<h2 style="padding: 5px 16px 5px 16px; font-weight: normal;display: inline-block;text-align:left;">
|
||||||
|
${label_text}
|
||||||
|
</h2>
|
||||||
|
<button id="${key}" value=${enabled} class="material-button" style="display:inline-block;font-size:medium; float:right; background:${button_color}">
|
||||||
|
${button_text}
|
||||||
|
</button>
|
||||||
|
<br>`
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,13 @@ var grades;
|
|||||||
var current_semesters = {};
|
var current_semesters = {};
|
||||||
var departments = [];
|
var departments = [];
|
||||||
var should_open = false;
|
var should_open = false;
|
||||||
|
|
||||||
|
const default_options = {
|
||||||
|
"loadAll": true,
|
||||||
|
"courseConflictHighlight": true,
|
||||||
|
"storeWaitlist": true,
|
||||||
|
}
|
||||||
|
|
||||||
onStartup();
|
onStartup();
|
||||||
|
|
||||||
/* Handle messages and their commands from content and popup scripts*/
|
/* Handle messages and their commands from content and popup scripts*/
|
||||||
@@ -51,6 +58,12 @@ chrome.runtime.onMessage.addListener(function (request, sender, response) {
|
|||||||
response({open : should_open});
|
response({open : should_open});
|
||||||
should_open = false;
|
should_open = false;
|
||||||
break;
|
break;
|
||||||
|
case "getOptionsValue":
|
||||||
|
getOptionsValue(request.key, response);
|
||||||
|
break;
|
||||||
|
case "setOptionsValue":
|
||||||
|
setOptionsValue(request.key, request.value, response);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
const method = request.method ? request.method.toUpperCase() : "GET";
|
const method = request.method ? request.method.toUpperCase() : "GET";
|
||||||
@@ -73,37 +86,19 @@ chrome.runtime.onMessage.addListener(function (request, sender, response) {
|
|||||||
/* Initially set the course data in storage */
|
/* Initially set the course data in storage */
|
||||||
chrome.runtime.onInstalled.addListener(function (details) {
|
chrome.runtime.onInstalled.addListener(function (details) {
|
||||||
if (details.reason == "install") {
|
if (details.reason == "install") {
|
||||||
|
setDefaultOptions();
|
||||||
chrome.storage.sync.get('savedCourses', function (data) {
|
chrome.storage.sync.get('savedCourses', function (data) {
|
||||||
if (!data.savedCourses) {
|
if (!data.savedCourses) {
|
||||||
var arr = new Array();
|
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
savedCourses: arr
|
savedCourses: new Array()
|
||||||
}, function () {
|
}, function () {
|
||||||
console.log('initial course list');
|
console.log('initial course list');
|
||||||
});
|
});
|
||||||
chrome.storage.sync.set({
|
|
||||||
courseConflictHighlight: true
|
|
||||||
}, function () {
|
|
||||||
console.log('initial highlighting: true');
|
|
||||||
});
|
|
||||||
chrome.storage.sync.set({
|
|
||||||
loadAll: true
|
|
||||||
}, function () {
|
|
||||||
console.log('initial loadAll: true');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (details.reason == "update") {
|
} else if (details.reason == "update") {
|
||||||
console.log("updated");
|
console.log("updated");
|
||||||
chrome.storage.sync.get('loadAll', function (data) {
|
setDefaultOptions();
|
||||||
if (data.loadAll == undefined) {
|
|
||||||
chrome.storage.sync.set({
|
|
||||||
loadAll: true
|
|
||||||
}, function () {
|
|
||||||
console.log('initial loadAll: true');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -124,6 +119,51 @@ function onStartup(){
|
|||||||
getCurrentDepartments();
|
getCurrentDepartments();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getOptionsValue(key, sendResponse){
|
||||||
|
chrome.storage.sync.get('options', function (data) {
|
||||||
|
if (!data.options) {
|
||||||
|
setDefaultOptions();
|
||||||
|
} else {
|
||||||
|
sendResponse({
|
||||||
|
'value': data.options[key]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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(){
|
function getCurrentSemesters(){
|
||||||
$.get('https://registrar.utexas.edu/schedules', function (response) {
|
$.get('https://registrar.utexas.edu/schedules', function (response) {
|
||||||
if (response) {
|
if (response) {
|
||||||
|
|||||||
@@ -7,9 +7,13 @@ var done_loading = true;
|
|||||||
|
|
||||||
var next = $("#next_nav_link");
|
var next = $("#next_nav_link");
|
||||||
if (next) {
|
if (next) {
|
||||||
chrome.storage.sync.get('loadAll', function (data) {
|
chrome.runtime.sendMessage({
|
||||||
if (data.loadAll)
|
command: "getOptionsValue",
|
||||||
|
key: "loadAll",
|
||||||
|
}, function (response) {
|
||||||
|
if(response.value){
|
||||||
$('[title*="next listing"]').remove();
|
$('[title*="next listing"]').remove();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,8 +185,11 @@ function saveCourse() {
|
|||||||
|
|
||||||
/* 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 updateListConflictHighlighting(start = 0) {
|
function updateListConflictHighlighting(start = 0) {
|
||||||
chrome.storage.sync.get('courseConflictHighlight', function (data) {
|
chrome.runtime.sendMessage({
|
||||||
let canHighlight = data.courseConflictHighlight;
|
command: "getOptionsValue",
|
||||||
|
key: "courseConflictHighlight",
|
||||||
|
}, function (response) {
|
||||||
|
let canHighlight = response.value;
|
||||||
$('table').find('tr').each(function (i) {
|
$('table').find('tr').each(function (i) {
|
||||||
if (i >= start) {
|
if (i >= start) {
|
||||||
if (!($(this).find('td').hasClass("course_header")) && $(this).has('th').length == 0) {
|
if (!($(this).find('td').hasClass("course_header")) && $(this).has('th').length == 0) {
|
||||||
@@ -459,8 +466,11 @@ function getDescription(course_info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadNextPages() {
|
function loadNextPages() {
|
||||||
chrome.storage.sync.get('loadAll', function (data) {
|
chrome.runtime.sendMessage({
|
||||||
if (data.loadAll) {
|
command: "getOptionsValue",
|
||||||
|
key: "loadAll",
|
||||||
|
}, function (response) {
|
||||||
|
if(response.value){
|
||||||
let link = next.prop('href');
|
let link = next.prop('href');
|
||||||
if (done_loading && next && link) {
|
if (done_loading && next && link) {
|
||||||
toggleLoadingPage(true);
|
toggleLoadingPage(true);
|
||||||
|
|||||||
26
js/import.js
26
js/import.js
@@ -5,9 +5,12 @@ $(function () {
|
|||||||
sem = waitlist ? $('[name="s_ccyys"]').val() : $("option[selected='selected']").val();
|
sem = waitlist ? $('[name="s_ccyys"]').val() : $("option[selected='selected']").val();
|
||||||
if (waitlist) {
|
if (waitlist) {
|
||||||
$("[href='#top']").before(Template.Import.import_button());
|
$("[href='#top']").before(Template.Import.import_button());
|
||||||
|
$("[name='wl_see_my_waitlists']").before(Template.import.store_waitlist_message());
|
||||||
$("[name='wl_see_my_waitlists']").after(Template.Import.waitlist_import_button());
|
$("[name='wl_see_my_waitlists']").after(Template.Import.waitlist_import_button());
|
||||||
} else
|
extractWaitlistInfo();
|
||||||
|
} else {
|
||||||
$("table").after(Template.Import.import_button());
|
$("table").after(Template.Import.import_button());
|
||||||
|
}
|
||||||
$("#import").prepend("<div id='snackbar'>import snackbar..</div>");
|
$("#import").prepend("<div id='snackbar'>import snackbar..</div>");
|
||||||
|
|
||||||
$("#import").click(function () {
|
$("#import").click(function () {
|
||||||
@@ -28,6 +31,27 @@ $(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function extractWaitlistInfo(){
|
||||||
|
let class_boxes = $("[name='wl_see_my_waitlists']>table");
|
||||||
|
let waitlist_info = [];
|
||||||
|
$(class_boxes).each(function(){
|
||||||
|
let data = $(this).find('tr.tb span');
|
||||||
|
let unique_num = $(data[0]).text().trim();
|
||||||
|
let class_name = $(data[1]).text().trim().split('\n').filter(part => part.trim() != '').map(part => part.trim()).join(' ');
|
||||||
|
let waitlist_size = $(this).find('tr.tbon:eq(2) td:eq(1)').text().trim().split(' of ')[1];
|
||||||
|
|
||||||
|
waitlist_info.push({
|
||||||
|
"id": unique_num,
|
||||||
|
"class": class_name,
|
||||||
|
"wait": waitlist_size,
|
||||||
|
"time": moment().format('DD-MM-YYYY HH:mm:ss')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
console.log(waitlist_info);
|
||||||
|
return waitlist_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function importButtonAnimation(button) {
|
function importButtonAnimation(button) {
|
||||||
let is_waitlisted_button = $(button).attr('id') == "import_waitlist";
|
let is_waitlisted_button = $(button).attr('id') == "import_waitlist";
|
||||||
let return_text = is_waitlisted_button ? Text.waitlist_button_text_default : Text.button_text_default;
|
let return_text = is_waitlisted_button ? Text.waitlist_button_text_default : Text.button_text_default;
|
||||||
|
|||||||
@@ -1,64 +1,37 @@
|
|||||||
var manifestData = chrome.runtime.getManifest();
|
var manifestData = chrome.runtime.getManifest();
|
||||||
$("#version").text(manifestData.version);
|
$("#version").text(manifestData.version);
|
||||||
chrome.storage.sync.get('courseConflictHighlight', function (data) {
|
|
||||||
if (data.courseConflictHighlight) {
|
chrome.storage.sync.get('options', function(data){
|
||||||
off('courseConflictHighlight');
|
if(data.options){
|
||||||
} else {
|
console.log(data.options);
|
||||||
on('courseConflictHighlight');
|
Object.keys(data.options).forEach(key => {
|
||||||
}
|
let enabled = data.options[key];
|
||||||
|
$('#options_container').append(Template.Options.options_row(key, enabled));
|
||||||
});
|
});
|
||||||
chrome.storage.sync.get('loadAll', function (data) {
|
|
||||||
if (data.loadAll) {
|
|
||||||
off('loadAll');
|
|
||||||
} else {
|
|
||||||
on('loadAll');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#togglecourseConflictHighlight").click(function () {
|
$("body").on("click","button",function(){
|
||||||
var action = $("#togglecourseConflictHighlight").text();
|
let key = $(this).attr('id');
|
||||||
if (action == "Turn Off") {
|
let old_status = $(this).val() === 'true';
|
||||||
chrome.storage.sync.set({
|
let new_status = !old_status;
|
||||||
courseConflictHighlight: false
|
chrome.runtime.sendMessage({
|
||||||
}, function () {
|
command: "setOptionsValue",
|
||||||
on('courseConflictHighlight');
|
key: key,
|
||||||
});
|
value: new_status
|
||||||
} else {
|
}, function (response) {
|
||||||
chrome.storage.sync.set({
|
console.log(response.value);
|
||||||
courseConflictHighlight: true
|
toggle(key, response.value)
|
||||||
}, function () {
|
|
||||||
off('courseConflictHighlight');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
updateAllTabsCourseList();
|
updateAllTabsCourseList();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$("#toggleloadAll").click(function () {
|
|
||||||
var action = $("#toggleloadAll").text();
|
|
||||||
if (action == "Turn Off") {
|
|
||||||
chrome.storage.sync.set({
|
|
||||||
loadAll: false
|
|
||||||
}, function () {
|
|
||||||
on('loadAll');
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
chrome.storage.sync.set({
|
|
||||||
loadAll: true
|
|
||||||
}, function () {
|
|
||||||
off('loadAll');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function on(setting) {
|
function toggle(key, value) {
|
||||||
$("#toggle" + setting).text("Turn On");
|
let button_text = value ? "Turn Off": "Turn On";
|
||||||
$("#toggle" + setting).css("background", "#4CAF50");
|
let button_color = value ? Colors.closed : Colors.open ;
|
||||||
}
|
$(`#${key}`).text(button_text);
|
||||||
|
$(`#${key}`).css("background", button_color);
|
||||||
function off(setting) {
|
$(`#${key}`).val(value);
|
||||||
$("#toggle" + setting).text("Turn Off");
|
|
||||||
$("#toggle" + setting).css("background", "#F44336");
|
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
"matches": ["https://utexas.collegescheduler.com/*"]
|
"matches": ["https://utexas.collegescheduler.com/*"]
|
||||||
}, {
|
}, {
|
||||||
"css": ["css/styles.css"],
|
"css": ["css/styles.css"],
|
||||||
"js": ["js/config.js", "js/lib/moment.min.js", "js/lib/sql-memory-growth.js", "js/lib/highcharts.js", "js/lib/jquery-3.3.1.min.js", "js/Template.js", "js/util.js", "js/import.js"],
|
"js": ["js/config.js", "js/lib/moment.min.js", "js/lib/highcharts.js", "js/lib/jquery-3.3.1.min.js", "js/Template.js", "js/util.js", "js/import.js"],
|
||||||
"matches": ["https://utdirect.utexas.edu/registrar/waitlist/wl_see_my_waitlists.WBX", "https://utdirect.utexas.edu/registration/classlist.WBX*"]
|
"matches": ["https://utdirect.utexas.edu/registrar/waitlist/wl_see_my_waitlists.WBX", "https://utdirect.utexas.edu/registration/classlist.WBX*"]
|
||||||
}],
|
}],
|
||||||
"web_accessible_resources": [
|
"web_accessible_resources": [
|
||||||
|
|||||||
14
options.html
14
options.html
@@ -9,22 +9,14 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="card" style="width: 400px; margin-left:auto;margin-right: auto; height:auto;" id="header">
|
<div class="card" style="width: 400px; margin-left:auto;margin-right: auto; height:auto;" id="header">
|
||||||
<h2 style="padding:16px 16px 0px 16px;font-size: 20px"> <u>Options</u> </h2>
|
<h2 style="padding:16px 16px 0px 16px;font-size: 20px"> <u>Options</u> </h2>
|
||||||
<div>
|
<div id="options_container">
|
||||||
<h2 style="padding: 5px 16px 5px 16px; font-weight: normal;display: inline-block;text-align:left;">Conflict
|
|
||||||
Highlighting</h2>
|
|
||||||
<button id="togglecourseConflictHighlight" class="material-button"
|
|
||||||
style="float:right; display:inline-block;font-size:medium;background:#F44336;">Turn
|
|
||||||
Off</button>
|
|
||||||
<h2 style="padding: 5px 16px 16px 16px; font-weight: normal;display: inline-block;text-align:left;">Scroll To
|
|
||||||
Load More Courses</h2>
|
|
||||||
<button id="toggleloadAll" class="material-button"
|
|
||||||
style="float: right;display:inline-block;font-size:medium;background:#F44336;">Turn
|
|
||||||
Off</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p style="padding:0px 5px 5px 0px; float: right">(v<span id="version"></span>), Sriram Hariharan, 2018</p>
|
<p style="padding:0px 5px 5px 0px; float: right">(v<span id="version"></span>), Sriram Hariharan, 2018</p>
|
||||||
|
<script src="js/config.js"></script>
|
||||||
<script src="js/lib/jquery-3.3.1.min.js"></script>
|
<script src="js/lib/jquery-3.3.1.min.js"></script>
|
||||||
<script src="js/util.js"></script>
|
<script src="js/util.js"></script>
|
||||||
|
<script src="js/Template.js"></script>
|
||||||
<script src="js/options.js"></script>
|
<script src="js/options.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user