diff --git a/js/background.js b/js/background.js index ccb4e714..07b38421 100644 --- a/js/background.js +++ b/js/background.js @@ -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'); - 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(""+" #"+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(){ diff --git a/js/options.js b/js/options.js new file mode 100644 index 00000000..cacf7ab8 --- /dev/null +++ b/js/options.js @@ -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 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 + + + + + + +