options and more

This commit is contained in:
Sriram Hariharan
2018-07-18 20:07:08 -05:00
parent 5e39221c2c
commit 73cbbd1cfb
6 changed files with 107 additions and 71 deletions

View File

@@ -37,6 +37,9 @@ chrome.runtime.onInstalled.addListener(function() {
chrome.storage.sync.set({savedCourses: arr}, function() {
console.log('initial course list');
});
chrome.storage.sync.set({courseConflictHighlight: true}, function() {
console.log('initial highlighting: true');
});
});
/* Find all the conflicts in the courses and send them out/ if there is even a conflict*/
@@ -119,7 +122,6 @@ function remove(request, sender, sendResponse) {
var courses = data.savedCourses;
console.log(courses);
var index = 0;
console.log(courses.length);
while(index<courses.length && courses[index].unique != request.course.unique){
index++;
}

View File

@@ -29,35 +29,12 @@ $(document).ready( function() {
//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;
//if a course row, then add the extension button
$(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();
chrome.runtime.sendMessage({command: "isSingleConflict",dtarr: getDtarr(this),unique:uniquenum}, function(response) {
if(response.isConflict){
$(thisForm).find('td').each(function(){
$(this).css('color','#F44336');
$(this).css('text-decoration','line-through');
$(this).css('font-weight','normal');
});
}
else {
$(thisForm).find('td').each(function(){
$(this).css('color','black');
$(this).css('text-decoration','none');
$(this).css('font-weight','normal');
});
}
if(response.alreadyContains){
$(thisForm).find('td').each(function(){
$(this).css('color','#4CAF50');
$(this).css('text-decoration','none');
$(this).css('font-weight','bold');
});
}
});
}
});
//update the conflicts
update();
/*Handle the button clicks*/
$(".distButton").click(function(){
var row = $(this).closest('tr');
@@ -101,7 +78,7 @@ $(document).ready( function() {
/*Listen for update mssage coming from popup*/
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.command == "update"){
if (request.command == "updateCourseList"){
update();
}
});
@@ -109,34 +86,37 @@ $(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){
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){
$(thisForm).find('td').each(function(){
$(this).css('color','#F44336');
$(this).css('text-decoration','line-through');
$(this).css('font-weight','normal');
});
}
else {
$(thisForm).find('td').each(function(){
$(this).css('color','black');
$(this).css('text-decoration','none');
$(this).css('font-weight','normal');
});
}
if(response.alreadyContains){
$(thisForm).find('td').each(function(){
$(this).css('color','#4CAF50');
$(this).css('text-decoration','none');
$(this).css('font-weight','bold');
});
chrome.storage.sync.get('courseConflictHighlight', function(data) {
console.log(data.courseConflictHighlight);
$('table').find('tr').each(function(){
if(!($(this).find('td').hasClass("course_header")) && $(this).has('th').length == 0){
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 && data.courseConflictHighlight){
$(thisForm).find('td').each(function(){
$(this).css('color','#F44336');
$(this).css('text-decoration','line-through');
$(this).css('font-weight','normal');
});
}
else {
$(thisForm).find('td').each(function(){
$(this).css('color','black');
$(this).css('text-decoration','none');
$(this).css('font-weight','normal');
});
}
if(response.alreadyContains){
$(thisForm).find('td').each(function(){
$(this).css('color','#4CAF50');
$(this).css('text-decoration','none');
$(this).css('font-weight','bold');
});
}
});
}
});
}
});
}
@@ -204,7 +184,7 @@ function getCourseInfo(row){
/*Handle if on the individual course page*/
if(typeof coursename == 'undefined'){
coursename = $("#details h2").text();
profinit = profinit.substring(0,1);
profinit = $("table").find("td[data-th='Instructor']").text().split(", ")[1].substring(0,1);
profurl = document.URL;
}
getDescription();
@@ -291,17 +271,12 @@ function openDialog(dep,cls,sem,professor,res){
});
//set if no grade distribution
var data;
if(typeof res == 'undefined'){
if(typeof res == 'undefined' || profname == ""){
data = [];
}
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];
}
var modal = document.getElementById('myModal');
var span = document.getElementsByClassName("close")[0];
modal.style.display = "block";
@@ -319,12 +294,15 @@ function openDialog(dep,cls,sem,professor,res){
}
$("#title").append("<span style='color:"+color+";font-size:medium;'>"+" #"+uniquenum+"</>");
if(typeof profinit != "undefined" && profinit.length > 1){
profinit = profinit.substring(0,1);
}
var name;
if(profname == ""){
name = "Undecided Professor ";
}
else{
name = profinit+". "+profname.substring(0,1)+profname.substring(1).toLowerCase();
name = prettifyName();
}
$("#profname").text("with "+ name);
//close button
@@ -343,7 +321,7 @@ function openDialog(dep,cls,sem,professor,res){
text: null
},
subtitle: {
text: title
text: null
},
legend: {
enabled: false
@@ -405,7 +383,7 @@ function openDialog(dep,cls,sem,professor,res){
}, 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)
chart.renderer.text('Could not find distribution for this Instructor teaching this Course.', 100, 120)
.css({
fontSize: '20px',
align:'center',
@@ -435,6 +413,12 @@ function prettifyTitle(){
});
return output + " ("+department+" "+course_nbr+")";
}
/* Format the Professor Name */
function prettifyName() {
return profinit + ". "+profname.replace(/\w\S*/g, function(txt){
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
/*Get the course description from the profurl and highlight the important elements, as well as set the eCIS, and rmp links.*/
function getDescription(){

30
js/options.js Normal file
View File

@@ -0,0 +1,30 @@
chrome.storage.sync.get('courseConflictHighlight', function(data) {
if(data.courseConflictHighlight){
$("#toggleConflictHighlighting").text("Turn Off");
$("#toggleConflictHighlighting").css("background","#F44336");
}
else {
$("#toggleConflictHighlighting").text("Turn On");
$("#toggleConflictHighlighting").css("background","#4CAF50");
}
});
$("#toggleConflictHighlighting").click(function(){
var action = $("#toggleConflictHighlighting").text();
if(action == "Turn Off"){
chrome.storage.sync.set({courseConflictHighlight: false}, function() {
$("#toggleConflictHighlighting").text("Turn On");
$("#toggleConflictHighlighting").css("background","#4CAF50");
});
} else{
chrome.storage.sync.set({courseConflictHighlight: true}, function() {
$("#toggleConflictHighlighting").text("Turn Off");
$("#toggleConflictHighlighting").css("background","#F44336");
});
}
chrome.tabs.query({}, function(tabs) {
for(var i = 0; i<tabs.length; i++){
chrome.tabs.sendMessage(tabs[i].id, {command: "updateCourseList"});
}
});
});

View File

@@ -78,8 +78,8 @@ $(document).ready(function() {
});
/* 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;
$(thisForm).closest("ul").find("> p").remove();
chrome.runtime.sendMessage({command: "courseStorage",course: courses[$(thisForm).closest("li").attr("id")], action:"remove"}, function(response) {
$(thisForm).closest("li").fadeOut(200);
if($(thisForm).closest("ul").children(':visible').length===1){
@@ -88,8 +88,10 @@ $(document).ready(function() {
});
}
updateConflicts();
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {command: "update"});
chrome.tabs.query({}, function(tabs) {
for(var i = 0; i<tabs.length; i++){
chrome.tabs.sendMessage(tabs[i].id, {command: "updateCourseList"});
}
});
});
});
@@ -108,7 +110,7 @@ $(document).ready(function() {
chrome.tabs.create({ 'url': 'https://registrar.utexas.edu/schedules'});
});
$("#open").click(function(){
chrome.tabs.create({ 'url': 'chrome://extensions/?options=' + chrome.runtime.id });
chrome.tabs.create({ 'url': "options.html"});
});
});
@@ -142,8 +144,10 @@ 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) {
chrome.tabs.sendMessage(tabs[0].id, {command: "update"});
chrome.tabs.query({}, function(tabs) {
for(var i = 0; i<tabs.length; i++){
chrome.tabs.sendMessage(tabs[i].id, {command: "updateCourseList"});
}
});
console.log("cleared");
$("#courseList").fadeOut(300,function(){