search by unique number

This commit is contained in:
sghsri
2018-12-12 21:03:49 -06:00
parent 8d4775fc8a
commit 3984c26df6
10 changed files with 212 additions and 70 deletions

View File

@@ -35,6 +35,8 @@ body {
bottom: 0;
right: 0;
float: right;
display: flex;
vertical-align: middle;
margin-right: 5px;
}
.matbut {
@@ -149,3 +151,18 @@ body {
.card:focus:not(:active)::after {
animation: ripple 1s ease-out;
}
input[type=number]{
width: 80px;
font-weight: bold;
}
::placeholder{
};
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
margin: 0;
}

View File

@@ -35,6 +35,7 @@
font-size: x-large;
font-weight: bold;
padding-top: 5px;
line-height: 1;
padding-left: 5px;
margin: 5px 0px 5px 0px;
}
@@ -49,7 +50,7 @@
margin-left: 5px;
padding-bottom: 5px;
font-size: medium;
margin-top: 10px;
margin-top: 5px;
}
.dateTimePlace {

View File

@@ -1,31 +1,31 @@
/* Handle messages and their commands from content and popup scripts*/
chrome.runtime.onMessage.addListener(function (request, sender, response) {
if (request.command == "courseStorage") {
switch(request.command){
case "courseStorage":
if (request.action == "add") {
add(request, sender, response);
}
if (request.action == "remove") {
remove(request, sender, response);
}
} else if (request.command == "isSingleConflict") {
break;
case "isSingleConflict":
isSingleConflict(request.dtarr, request.unique, response);
} else if (request.command == "checkConflicts") {
break;
case "checkConflicts":
checkConflicts(response);
} else if (request.command == "updateStatus") {
break;
case "updateStatus":
updateStatus();
} else if (request.command == "alreadyContains") {
break;
case "alreadyContains":
alreadyContains(request.unique, response);
} else if (request.command == "updateTabs") {
break;
case "updateCourseList":
updateTabs();
} else if(request.command == "updateCourseList"){
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(tabs[i].id, {
command: "updateCourseList"
});
}
});
} else {
break;
default:
const xhr = new XMLHttpRequest();
const method = request.method ? request.method.toUpperCase() : "GET";
xhr.open(method, request.url, true);
@@ -35,6 +35,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, response) {
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
xhr.send(request.data);
break;
}
return true;
});

View File

@@ -65,7 +65,7 @@ function getInfo(classurl) {
action: "add"
}, function () {
chrome.runtime.sendMessage({
command: "updateTabs"
command: "updateCourseList"
});
});
}

View File

@@ -1,3 +1,5 @@
var manifestData = chrome.runtime.getManifest();
$("#version").text(manifestData.version);
chrome.storage.sync.get('courseConflictHighlight', function(data) {
if(data.courseConflictHighlight){
off();

View File

@@ -6,9 +6,7 @@ setCourseList();
// var modhtml = '<div class=modal id=myModal><div class=modal-content><span class=close>×</span><div class=card><div class=cardcontainer></div></div></div></div>';
// $("#html").prepend(modhtml);
var emptyText = ["Doesn't Look Like Anything To Me.", "You Can't Fail Classes You're Not In."];
$("#main").text(emptyText[Math.floor(Math.random()*emptyText.length)]);
function setCourseList(){
$("#courseList").empty()
chrome.storage.sync.get('savedCourses', function (data) {
@@ -17,9 +15,8 @@ function setCourseList(){
if (courses.length != 0) {
$("#empty").hide();
$("#courseList").show();
} else{
$("#empty").show();
showEmpty();
}
// build and append the course list element
for (var i = 0; i < courses.length; i++) {
@@ -44,6 +41,19 @@ function setCourseList(){
});
}
function showEmpty(){
var emptyText = ["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?']
$("#courseList").hide();
$("#empty").fadeIn(200);
$("#main").html(emptyText[Math.floor(Math.random()*emptyText.length)]);
}
/* prettify the name for the conflict messages*/
function getSimpleName(coursename, unique) {
var department = coursename.substring(0, coursename.search(/\d/) - 2);
@@ -118,9 +128,7 @@ $(document).ready(function () {
}, function (response) {
$(thisForm).closest("li").fadeOut(200);
if ($(thisForm).closest("ul").children(':visible').length === 1) {
$("#courseList").fadeOut(300, function () {
$("#empty").fadeIn(200);
});
showEmpty();
}
updateConflicts();
chrome.tabs.query({}, function (tabs) {
@@ -154,29 +162,28 @@ $(document).ready(function () {
$("#impexp").click(function(){
if($("#impexp>i").text() == 'close'){
$(".settings").find('#import').remove();
$(".settings").find('#export').remove();
$('#import').hide();
$('#export').hide();
$("#impexp>i").text('import_export');
} else{
$("#impexp>i").text('close');
$(".settings").prepend(`
</button><button title='Import' style="background-color:white;" class="settingsbut" id='import'>
<i style='color:#FF9800' class="material-icons">
arrow_upward
</i>
</button>
<button title='Export' style="background-color:white;" class="settingsbut" id='export'>
<i style='color:#FF9800' class="material-icons">
arrow_downward
</i>
</button>
`);
$('#import').show();
$('#export').show();
}
})
$(".settings").on('click', '#import', function () {
});
$("#search").click(function(){
if($("#search>i").text() == 'close'){
$("#search>i").text('search');
$("#class_id").hide();
} else{
$("#search>i").text('close');
$("#class_id").show();
}
});
$('#import').click(function () {
$("#importOrig").click();
});
$(".settings").on('click', '#export',function () {
$('#export').click(function () {
chrome.storage.sync.get('savedCourses', function (data) {
var exportArray = JSON.stringify(data.savedCourses, null, 4);
var exportlink = document.createElement('a');
@@ -186,6 +193,18 @@ $(document).ready(function () {
exportlink.click();
});
});
$("#class_id").on("keyup", function(e){
if(e.keyCode == 13){
var unique = $(this).val();
if(!isNaN(unique)){
if(unique.length == 5){
getInfo("20192", unique);
return;
}
}
alert("Invalid Input");
}
})
$("#open").click(function () {
chrome.tabs.create({
'url': "options.html"
@@ -198,6 +217,7 @@ $(document).ready(function () {
});
});
$("#importOrig").change(function(e){
var files = e.target.files;
var reader = new FileReader();
@@ -216,7 +236,7 @@ $("#importOrig").change(function(e){
});
}
});
setCourseList(impCourses);
setCourseList();
}
} catch(err){
@@ -314,7 +334,90 @@ function clear() {
});
$("#courseList").empty()
console.log("cleared");
$("#courseList").fadeOut(300, function () {
$("#empty").fadeIn(200);
});
showEmpty();
}
/*Course object for passing to background*/
function Course(coursename, unique, profname, datetimearr, status, link, registerlink) {
this.coursename = coursename;
this.unique = unique;
this.profname = profname;
this.datetimearr = datetimearr;
this.status = status;
this.link = link;
this.registerlink = registerlink;
}
function getInfo(sem, unique) {
var link = `https://utdirect.utexas.edu/apps/registrar/course_schedule/${sem}/${unique}/`;
var xhr = new XMLHttpRequest();
xhr.open("GET", link, false);
xhr.send();
var response = xhr.responseText;
if (response) {
var output = "";
var object = $('<div/>').html(response).contents();
var c = getCourseObject(object, link);
console.log(c);
chrome.runtime.sendMessage({
command: "courseStorage",
course: c,
action: "add"
}, function () {
chrome.runtime.sendMessage({
command: "updateCourseList"
});
setCourseList();
});
}
}
/*For a row, get all the course information and add the date-time-lines*/
function getCourseObject(object, link) {
let coursename = object.find("#details h2").text();
let uniquenum = object.find('td[data-th="Unique"]').text();
let profname = object.find("td[data-th='Instructor']").text().split(', ')[0];
if (profname.indexOf(" ") == 0) {
profname = profname.substring(1);
}
let datetimearr = getDtarr(object);
let status = object.find('td[data-th="Status"]').text();
let indlink = link;
let registerlink = object.find('td[data-th="Add"] a').prop('href');
return new Course(coursename, uniquenum, profname, datetimearr, status, indlink, registerlink);
}
/* For a row, get the date-time-array for checking conflicts*/
function getDtarr(object) {
var numlines = object.find('td[data-th="Days"]>span').length;
var dtarr = [];
for (var i = 0; i < numlines; i++) {
var date = object.find('td[data-th="Days"]>span:eq(' + i + ')').text();
var time = object.find('td[data-th="Hour"]>span:eq(' + i + ')').text();
var place = object.find('td[data-th="Room"]>span:eq(' + i + ')').text();
for (var j = 0; j < date.length; j++) {
var letter = date.charAt(j);
var day = "";
if (letter == "T" && j < date.length - 1 && date.charAt(j + 1) == "H") {
dtarr.push(["TH", convertTime(time), place]);
} else {
if (letter != "H") {
dtarr.push([letter, convertTime(time), place]);
}
}
}
}
return dtarr;
}
/*Convert time to 24hour format*/
function convertTime(time) {
var converted = time.replace(/\./g, '').split("-");
for (var i = 0; i < 2; i++) {
converted[i] = moment(converted[i], ["h:mm A"]).format("HH:mm");
}
return converted;
}

View File

@@ -20,13 +20,12 @@
"js": ["js/moment.min.js", "js/sql-memory-growth.js", "js/highcharts.js", "js/jquery-3.3.1.min.js", "js/import.js"],
"matches": ["https://utdirect.utexas.edu/registrar/waitlist/wl_see_my_waitlists.WBX", "https://utdirect.utexas.edu/registration/classlist.WBX*"]
}
],
"web_accessible_resources": [
"grades.db", "images/disticon.png"
],
"background": {
"scripts": ["js/background.js"],
"scripts": ["js/background.js", "js/moment.min.js", "js/jquery-3.3.1.min.js"],
"persistent": true
},
"browser_action": {

View File

@@ -10,7 +10,7 @@
<h2 style="padding: 5px 16px 16px 16px; font-weight: normal;display: inline-block;text-align:left;">Conflict Highlighting</h2>
<button id="toggleConflictHighlighting" class="matbut" style="margin-left: 20%;text-align:right;display:inline-block;font-size:medium;background:#F44336;">Turn Off</button>
<p style="padding:0px 5px 5px 0px; float: right">Made by 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/jquery-3.3.1.min.js"></script>
<script src="js/options.js"></script>
</body>

View File

@@ -26,8 +26,26 @@
</h2>
<div style=" margin-bottom: 0px; display:inline-block"></div>
<input type="file" id="importOrig" accept=".json" style="display:none"/>
<div class="settings">
<input type="text" id="class_id" name="class_id" maxlength="5"
style="display:none;text-indent: 10px;border-style: solid; border-color: #FF9800;" placeholder="Unique #?"></input>
<button title='Search' style="background-color:white;" class="settingsbut" id='search'>
<i style='color:#FF9800' class="material-icons">
search
</i>
</button>
<button title='Import' style="background-color:white; display:none;" class="settingsbut" id='import'>
<i style='color:#FF9800' class="material-icons">
arrow_upward
</i>
</button>
<button title='Export' style="background-color:white; display:none;" class="settingsbut"id='export'>
<i style='color:#FF9800' class="material-icons">
arrow_downward
</i>
</button>
<button title='Import/Export' style="background-color:white;" class="settingsbut" id='impexp'>
<i style='color:#FF9800' class="material-icons">
import_export

3
todo
View File

@@ -5,7 +5,7 @@ FEATURES:
- work on multiple schedules
- search by unique number
- all semester's grade distribution
- Easter egg, no course messages
- clean upcalendar export and add more options to screen
BUGS TO FIX:
- Fix the update/install bug
@@ -22,3 +22,4 @@ DONE/FIXED:
- import courses from class schedule screen
- import into and export from UT registration plus
- Showing the icon on the flags pages
- Easter egg, no course messages