cleaning up and comments

This commit is contained in:
Sriram Hariharan
2018-07-17 01:17:33 -05:00
parent add9171851
commit ce87d11578
7 changed files with 174 additions and 169 deletions

View File

@@ -36,7 +36,6 @@
background: #FF9800;
}
/* Ripple magic */
.matbut{
position: relative;
overflow: hidden;

View File

@@ -1,15 +1,14 @@
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
display: none;
position: fixed;
z-index: 1;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%; /* Full height */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
height: 100%;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
}
.modal-content {
@@ -69,18 +68,15 @@
}
.card {
/* Add shadows to create the "card" effect */
transition: 0.3s;
margin-bottom: 10px;
box-shadow:0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12)
}
/* On mouse-over, add a deeper shadow */
.card:hover {
box-shadow:0 4px 10px 0 rgba(0,0,0,0.2),0 4px 20px 0 rgba(0,0,0,0.19)
}
/* Add some padding inside the card container */
.cardcontainer {
padding: 2px 16px;
transition:width 300ms ease-in-out, height 300ms ease-in-out;
@@ -101,7 +97,6 @@
display:inline-block;
}
/* Material style */
.matbut {
border: none;
outline: none;
@@ -116,7 +111,6 @@
background: #FF9800;
}
/* Ripple magic */
.matbut{
position: relative;
overflow: hidden;

View File

@@ -1,3 +1,4 @@
/* Handle messages and their commands from content and popup scripts*/
chrome.runtime.onMessage.addListener(function(request, sender, response) {
if(request.command == "courseStorage") {
if(request.action == "add"){
@@ -30,6 +31,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, response) {
return true;
});
/* Initially set the course data in storage */
chrome.runtime.onInstalled.addListener(function() {
var arr = new Array();
chrome.storage.sync.set({savedCourses: arr}, function() {
@@ -37,6 +39,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, response) {
});
});
/* 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) {
var conflicts = [];
@@ -58,6 +61,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) {
var courses = data.savedCourses;
@@ -80,6 +84,7 @@ function isSingleConflict(currdatearr, unique, sendResponse){
});
}
/* Check if conflict between two date-time-arrs*/
function isConflict(adtarr, bdtarr){
for(var i = 0; i<adtarr.length;i++){
var currday = adtarr[i][0];
@@ -97,6 +102,7 @@ function isConflict(adtarr, bdtarr){
return false;
}
/* Add the requested course to the storage*/
function add(request, sender, sendResponse) {
chrome.storage.sync.get('savedCourses', function(data) {
var courses = data.savedCourses;
@@ -106,6 +112,8 @@ function add(request, sender, sendResponse) {
sendResponse({done:"Added: ("+request.course.unique+") "+request.course.coursename,label:"Remove Course -"});
});
}
/* Find and Remove the requested course from the storage*/
function remove(request, sender, sendResponse) {
chrome.storage.sync.get('savedCourses', function(data) {
var courses = data.savedCourses;
@@ -121,6 +129,7 @@ function remove(request, sender, sendResponse) {
});
}
/* Find if the unique is already contained within the storage*/
function alreadyContains(unique,sendResponse){
chrome.storage.sync.get('savedCourses', function(data) {
var courses = data.savedCourses;

View File

@@ -26,18 +26,16 @@ $(document).ready( function() {
var modhtml ='<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="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=""><ul class=description id="description" style="list-style-type:disc"></ul></div></div><div class=card ><div id="chartcontainer" class=cardcontainer><div id=chart></div></div></div></div>';
$("#container").prepend(modhtml);
$("#myModal").prepend("<div id='snackbar'>defaultmessage..</div>");
//go through all the rows in the list
$('table').find('tr').each(function(){
if(!($(this).find('td').hasClass("course_header")) && $(this).has('th').length == 0){
//if a course row, then add the extension button and do something if that course has been "saved"
var thisForm = this;
$(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>');
var uniquenum = $(this).find('td[data-th="Unique"]').text();
console.log(uniquenum);
chrome.runtime.sendMessage({command: "isSingleConflict",dtarr: getDtarr(this),unique:uniquenum}, function(response) {
if(response.isConflict){
//DO SOMETHING IF ALREADY CONTAINS
$(thisForm).find('td').each(function(){
// $(this).css('font-weight','bold');
$(this).css('color','#F44336');
$(this).css('text-decoration','line-through');
$(this).css('font-weight','normal');
@@ -45,7 +43,6 @@ $(document).ready( function() {
}
else {
$(thisForm).find('td').each(function(){
// $(this).css('font-weight','bold');
$(this).css('color','black');
$(this).css('text-decoration','none');
$(this).css('font-weight','normal');
@@ -53,7 +50,6 @@ $(document).ready( function() {
}
if(response.alreadyContains){
$(thisForm).find('td').each(function(){
// $(this).css('font-weight','bold');
$(this).css('color','#4CAF50');
$(this).css('text-decoration','none');
$(this).css('font-weight','bold');
@@ -62,7 +58,7 @@ $(document).ready( function() {
});
}
});
/*Handle the button clicks*/
$(".distButton").click(function(){
var row = $(this).closest('tr');
getCourseInfo(row);
@@ -95,12 +91,14 @@ $(document).ready( function() {
window.open(eCISLink);
}, butdelay);
});
/*Close Modal when hit escape*/
$(document).keydown(function(e) {
if (e.keyCode == 27) {
$("#myModal").fadeOut(fadetime);
}
$("#snackbar").attr("class","");
});
/*Listen for update mssage coming from popup*/
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.command == "update"){
@@ -109,17 +107,15 @@ $(document).ready( function() {
});
});
/* 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(){
$('table').find('tr').each(function(){
if(!($(this).find('td').hasClass("course_header")) && $(this).has('th').length == 0){
//if a course row, then add the extension button and do something if that course has been "saved"
var thisForm = this;
var uniquenum = $(this).find('td[data-th="Unique"]').text();
chrome.runtime.sendMessage({command: "isSingleConflict",dtarr: getDtarr(this),unique:uniquenum}, function(response) {
if(response.isConflict){
//DO SOMETHING IF ALREADY CONTAINS
$(thisForm).find('td').each(function(){
// $(this).css('font-weight','bold');
$(this).css('color','#F44336');
$(this).css('text-decoration','line-through');
$(this).css('font-weight','normal');
@@ -127,7 +123,6 @@ function update(){
}
else {
$(thisForm).find('td').each(function(){
// $(this).css('font-weight','bold');
$(this).css('color','black');
$(this).css('text-decoration','none');
$(this).css('font-weight','normal');
@@ -135,18 +130,17 @@ function update(){
}
if(response.alreadyContains){
$(thisForm).find('td').each(function(){
// $(this).css('font-weight','bold');
$(this).css('color','#4CAF50');
$(this).css('text-decoration','none');
$(this).css('font-weight','bold');
});
}
});
}
});
}
/* For a row, get the date-time-array for checking conflicts*/
function getDtarr(row){
var numlines = $(row).find('td[data-th="Days"]>span').length;
var dtarr = [];
@@ -170,6 +164,7 @@ function getDtarr(row){
return dtarr;
}
/*Course object for passing to background*/
function Course(coursename, unique, profname,datetimearr, status, link){
this.coursename = coursename;
this.unique = unique;
@@ -179,6 +174,7 @@ function Course(coursename, unique, profname,datetimearr, status, link){
this.link = link;
}
/*For a row, get all the course information and add the date-time-lines*/
function getCourseInfo(row){
$(".dateTimePlace").remove();
$('table').find('tr').each(function(){
@@ -201,11 +197,11 @@ function getCourseInfo(row){
var time = $(this).find('td[data-th="Hour"]>span:eq('+i+')').text();
var place = $(this).find('td[data-th="Room"]>span:eq('+i+')').text();
$("#topbuttons").before('<h2 class="dateTimePlace">'+makeLine(date,time,place)+'</th>');
// makeLine(date,time,place);
}
return false;
}
});
/*Handle if on the individual course page*/
if(typeof coursename == 'undefined'){
coursename = $("#details h2").text();
profinit = profinit.substring(0,1);
@@ -216,7 +212,7 @@ function getCourseInfo(row){
course_nbr = coursename.substring(coursename.search(/\d/),coursename.indexOf(" ",coursename.search(/\d/)));
}
//THIS CODE IS EXTREMELY MESSY, CLEAN UP GACK
/* Make the day-time-arr and make the text for the date-time-line*/
function makeLine(date, time, place){
var arr = [];
var output = "";
@@ -260,6 +256,7 @@ function makeLine(date, time, place){
return output + " at "+time.replace(/\./g,'').replace(/\-/g,' to ')+" in "+"<a style='font-size:medium' target='_blank' href='"+"https://maps.utexas.edu/buildings/UTM/"+building+"''>"+building+"</>";
}
/*Convert time to 24hour format*/
function convertTime(time){
var converted = time.replace(/\./g,'').split("-");
for(var i = 0; i<2;i++){
@@ -267,6 +264,8 @@ function convertTime(time){
}
return converted;
}
/*Query the grades database*/
function getDistribution(){
var query = "select * from agg";
query += " where dept like '%"+department+"%'";
@@ -278,8 +277,10 @@ function getDistribution(){
openDialog(department,coursename,"aggregate",profname,res);
}
/*Open the modal and show all the data*/
function openDialog(dep,cls,sem,professor,res){
$("#myModal").fadeIn(fadetime);
//initial text on the "save course button"
chrome.runtime.sendMessage({command: "alreadyContains",unique: uniquenum}, function(response) {
if(response.alreadyContains){
$("#saveCourse").text("Remove Course -");
@@ -288,6 +289,7 @@ function openDialog(dep,cls,sem,professor,res){
$("#saveCourse").text("Add Course +");
}
});
//set if no grade distribution
var data;
if(typeof res == 'undefined'){
data = [];
@@ -295,6 +297,7 @@ function openDialog(dep,cls,sem,professor,res){
else{
data = res.values[0];
}
//if undefined professor, then pick the distribution for the prof with the largest number of overall student entries
var title = null
if(profname == "" && typeof res != 'undefined'){
title = res.values[0][1];
@@ -324,11 +327,12 @@ function openDialog(dep,cls,sem,professor,res){
name = profinit+". "+profname.substring(0,1)+profname.substring(1).toLowerCase();
}
$("#profname").text("with "+ name);
//close button
span.onclick = function() {
$("#myModal").fadeOut(200);
$("#snackbar").attr("class","");
}
//set up the chart
chart = Highcharts.chart('chart', {
chart: {
type: 'column',
@@ -397,10 +401,10 @@ function openDialog(dep,cls,sem,professor,res){
series: [{
name: 'Grades',
data: [{y: data[6], color: '#4CAF50'}, {y: data[7], color: '#8BC34A'}, {y: data[8], color: '#CDDC39'}, {y: data[9], color: '#FFEB3B'}, {y: data[10], color: '#FFC107'}, {y: data[11], color: '#FFA000'}, {y: data[12], color: '#F57C00'}, {y: data[13], color: '#FF5722'}, {y: data[14], color: '#FF5252'}, {y: data[15], color: '#E64A19'}, {y: data[16], color: '#F44336'}, {y: data[17], color: '#D32F2F'}]
}]
}, function(chart) { // on complete
if(data.length == 0){
//if no data, then show the message and hide the series
chart.renderer.text('Could not find distribution for this Instructor teaching this Course', 100, 120)
.css({
fontSize: '20px',
@@ -414,25 +418,25 @@ function openDialog(dep,cls,sem,professor,res){
});
}
}); // When the user clicks anywhere outside of the modal, close it
}); // When clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
$("#myModal").fadeOut(fadetime);
$("#snackbar").attr("class","");
}
}
}
/*Format the title*/
function prettifyTitle(){
val = department.length+course_nbr.length+3;
output = coursename.substring(val).replace(/\b\w*/g, function(txt){
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
return output + " ("+department+" "+course_nbr+")";
}
/*Get the course description from the profurl and highlight the important elements, as well as set the eCIS, and rmp links.*/
function getDescription(){
chrome.runtime.sendMessage({
method: "GET",
@@ -452,7 +456,6 @@ function getDescription(){
sentence = "<li style='font-style: italic; padding: 0px 5px 5px 5px;'>"+sentence+"</li>";
}
else if(sentence.indexOf("Restricted to") == 0){
//console.log(sentence);
sentence = "<li style='color:red; padding: 0px 5px 5px 5px;'>"+sentence+"</li>";
}
else{
@@ -482,15 +485,15 @@ function getDescription(){
}
/* Load the database*/
function loadDataBase(){
sql = window.SQL;
loadBinaryFile('grades.db', function(data){
var sqldb = new SQL.Database(data);
// Database is ready
grades = sqldb;
//console.log(grades.exec(query)[0]);
});
}
/* load the database from file */
function loadBinaryFile(path,success) {
var xhr = new XMLHttpRequest();
xhr.open("GET", chrome.extension.getURL(path), true);

View File

@@ -1,5 +1,7 @@
var courses;
// get the courses from storage
chrome.storage.sync.get('savedCourses', function(data) {
//find, build, and show the messages for the conflicts in the saved courses
chrome.runtime.sendMessage({command: "checkConflicts"}, function(response) {
var isConflicted = [];
if(response.isConflict){
@@ -20,7 +22,7 @@ chrome.storage.sync.get('savedCourses', function(data) {
if(courses.length != 0){
$("#empty").hide();
}
console.log(courses);
// build and append the course list element
for(var i = 0; i<courses.length;i++){
var color;
status = courses[i].status;
@@ -41,12 +43,14 @@ chrome.storage.sync.get('savedCourses', function(data) {
}
});
/* prettify the name for the conflict messages*/
function getSimpleName(coursename, unique){
var department = coursename.substring(0,coursename.search(/\d/)-2);
var course_nbr = coursename.substring(coursename.search(/\d/),coursename.indexOf(" ",coursename.search(/\d/)));
return department+" "+course_nbr+" ("+unique+")";
}
/* Update the conflict messages */
function updateConflicts(){
chrome.runtime.sendMessage({command: "checkConflicts"}, function(response) {
var isConflicted = [];
@@ -66,18 +70,18 @@ function updateConflicts(){
});
}
/* Handle the button clicks */
$(document).ready(function() {
$("#courseList li").click(function(){
//GACKY FIX
$(this).find("#listMoreInfo").click(function(){
window.open(courses[$(this).closest("li").attr("id")].link);
});
/* clear the conflict messages, then remove the course and updateConflicts. update the tabs*/
$(this).find("#listRemove").click(function(){
$(thisForm).closest("ul").find("> p").remove();
var thisForm = this;
chrome.runtime.sendMessage({command: "courseStorage",course: courses[$(thisForm).closest("li").attr("id")], action:"remove"}, function(response) {
$(thisForm).closest("li").fadeOut(200);
console.log($(thisForm).closest("ul").children(":visible").length);
$(thisForm).closest("ul").find("> p").remove();
if($(thisForm).closest("ul").children(':visible').length===1){
$("#courseList").fadeOut(300,function(){
$("#empty").fadeIn(200);
@@ -89,9 +93,9 @@ $(document).ready(function() {
});
});
});
/* Show the times popout and more info options*/
if($(this).find("#moreInfo").is(":hidden")){
$(this).find("#moreInfo").fadeIn(200);
//alert("hello");
}
else{
$(this).find("#moreInfo").fadeOut(200);
@@ -101,13 +105,14 @@ $(document).ready(function() {
clear();
});
$("#schedule").click(function(){
chrome.tabs.create({ 'url': 'https://utexas.collegescheduler.com/entry'});
chrome.tabs.create({ 'url': 'https://registrar.utexas.edu/schedules'});
});
$("#open").click(function(){
chrome.tabs.create({ 'url': 'chrome://extensions/?options=' + chrome.runtime.id });
});
});
/* convert from the dtarr and maek the time lines*/
function makeLine(index){
var datetimearr = courses[index].datetimearr;
//converted times back
@@ -116,23 +121,17 @@ function makeLine(index){
datetimearr[i][1][0] = moment(datetimearr[i][1][0], ["HH:mm"]).format("h:mm A");
datetimearr[i][1][1] = moment(datetimearr[i][1][1], ["HH:mm"]).format("h:mm A");
}
//console.log(datetimearr[0][0]);
for(var i = 0; i<datetimearr.length;i++){
//console.log(datetimearr[i][0]);
if(dtmap.has(String(datetimearr[i][1]))){
console.log(datetimearr[i][0]);
dtmap.set(String(datetimearr[i][1]),dtmap.get(String(datetimearr[i][1]))+datetimearr[i][0]);
}
else{
console.log(datetimearr[i][0]);
dtmap.set(String(datetimearr[i][1]),datetimearr[i][0]);
}
}
var output="";
var timearr = Array.from(dtmap.keys());
var dayarr = Array.from(dtmap.values());
console.log(timearr);
console.log(dayarr);
for(var i = 0; i<dayarr.length;i++){
output += "<span style='font-size:medium'>"+dayarr[i]+"</span>: <span style='float:right'>"+timearr[i].split(",")[0]+" to "+timearr[i].split(",")[1]+"</span><br>";
}
@@ -140,6 +139,7 @@ function makeLine(index){
}
/*Clear the list and the storage of courses*/
function clear(){
chrome.storage.sync.set({savedCourses: []});
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
@@ -148,6 +148,5 @@ function clear(){
console.log("cleared");
$("#courseList").fadeOut(300,function(){
$("#empty").fadeIn(200);
});
}

View File

@@ -1,9 +1,9 @@
{
"manifest_version": 2,
"name": "UT Course Extension",
"name": "UT Registration Plus",
"version": "0.1.0",
"description": "Chrome Extension to show more information on the UT Course catalog",
"description": "Improves the course registration process at the University of Texas at Austin!",
"permissions": [ "tabs",
"declarativeContent",
"storage",

View File

@@ -8,13 +8,14 @@
<div class="card" id="header">
<div id="buttons" style="padding: 5px 10px 5px 10px;display: flex;justify-content: space-between;">
<button id="clear" class="matbut" style="font-size:medium; background:#4CAF50;margin: 10px;">Clear All</button>
<button id="schedule" class="matbut" style="font-size:medium;background:#FF9800;margin: 10px">UT Planner</button>
<button id="schedule" class="matbut" style="font-size:medium;background:#FF9800;margin: 10px">Course List</button>
<button id="open" class="matbut" style="font-size:medium;background:#FFC107;margin: 10px;">Options</button>
</div>
</div>
<ul id= "courseList" style="list-style-type: none;padding: 5px;"></ul>
<h2 id="empty" style="font-weight: normal;font-size: large;margin: 60px 30px 40px 30px ;">Doesn't Look Like Anything To Me.<br>
<span style="font-size: small;display:table;margin:0 auto;font-weight: bold">(No Courses Saved)</span><h2>
<span style="font-size: small;display:table;margin:0 auto;font-weight: bold">(No Courses Saved)</span>
<h2>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/moment.min.js"></script>
<script src="js/popup.js"></script>