cleaned up some code

This commit is contained in:
Sriram Hariharan
2018-07-07 16:57:23 -05:00
parent 4d021c6d80
commit 8806e8d876
8 changed files with 68 additions and 43 deletions

View File

@@ -1,24 +1,19 @@
chrome.runtime.onMessage.addListener(function(request, sender, response) { chrome.runtime.onMessage.addListener(function(request, sender, response) {
const xhr = new XMLHttpRequest();
chrome.runtime.onMessage.addListener( const method = request.method ? request.method.toUpperCase() : "GET";
function (request, sender, sendResponse) { xhr.open(method, request.url, true);
console.log(sender.tab ? xhr.onload = () => response(xhr.responseText);
"from a content script:" + sender.tab.url : xhr.onerror = () => response(xhr.statusText);
"from the extension"); if (method == "POST") {
if (request.greeting == "hello") xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
sendResponse({ farewell: "goodbye" }); }
}); xhr.send(request.data);
const xhr = new XMLHttpRequest(); return true;
const method = request.method ? request.method.toUpperCase() : "GET";
xhr.open(method, request.url, true);
xhr.onload = () => response(xhr.responseText);
xhr.onerror = () => response(xhr.statusText);
if (method == "POST") {
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
xhr.send(request.data);
return true;
}); });
chrome.runtime.onInstalled.addListener(function() {
chrome.storage.sync.set({color: '#3aa757'}, function() {
console.log("The color is green.");
});
});

View File

@@ -11,7 +11,7 @@ var description;
$(document).ready( function() { $(document).ready( function() {
loadDataBase(); loadDataBase();
//make heading //make heading
$("table thead th:nth-child(8)").after('<th scope=col>Dist</th>'); $("table thead th:nth-child(9)").after('<th scope=col>Dist</th>');
var modhtml = '<div class=modal id=myModal><div class=modal-content><span class=close>×</span><div class=card><div class=cardcontainer><h2 class=title>Computer Fluency (C S 302)</h2><h2 class=profname>with Bruce Porter</h2><div class=topbuttons><button class=matbut id="rateMyProf"> RMP </button><button class=matbut id="eCIS"> eCIS </button><button class=matbut id="saveCourse"> Save Course </button></div></div></div><div class=card><div class=cardcontainer><h2 class=description></h2></div></div><div class=card><div class=cardcontainer><div id=chart></div></div></div></div>' var modhtml = '<div class=modal id=myModal><div class=modal-content><span class=close>×</span><div class=card><div class=cardcontainer><h2 class=title>Computer Fluency (C S 302)</h2><h2 class=profname>with Bruce Porter</h2><div class=topbuttons><button class=matbut id="rateMyProf"> RMP </button><button class=matbut id="eCIS"> eCIS </button><button class=matbut id="saveCourse"> Save Course </button></div></div></div><div class=card><div class=cardcontainer><h2 class=description></h2></div></div><div class=card><div class=cardcontainer><div id=chart></div></div></div></div>'
$("#container").prepend(modhtml); $("#container").prepend(modhtml);
//console.log(grades); //console.log(grades);
@@ -21,7 +21,8 @@ $(document).ready( function() {
} else if($(this).has('th').length == 0){ } else if($(this).has('th').length == 0){
var rating; var rating;
var profname = $(this).find('td').eq(4).text() + ""; var profname = $(this).find('td[data-th="Instructor"]').text() + "";
console.log(profname);
if(profname == ""){ if(profname == ""){
//console.log("No Professor"); //console.log("No Professor");
rating = "No Prof :("; rating = "No Prof :(";
@@ -32,15 +33,17 @@ $(document).ready( function() {
$(this).append('<td data-th="Dist"><input type="image" class="distButton" style="vertical-align: bottom;" width="30" height="30" src='+chrome.extension.getURL('disticon.png')+' /></td>'); $(this).append('<td data-th="Dist"><input type="image" class="distButton" style="vertical-align: bottom;" width="30" height="30" src='+chrome.extension.getURL('disticon.png')+' /></td>');
} }
}); });
$(this).find(".distButton").click(function(){ $(".distButton").click(function(){
//var coursename = $(this).closest(':has(.course_header)').find('.course_header');
//CLEAN UP, "gack"- Michael Scott
var row = $(this).closest('tr'); var row = $(this).closest('tr');
getCourseInfo(row); getCourseInfo(row);
//console.log(profname + " "+department+" "+course_nbr);
//console.log(coursename);
getDistribution(); getDistribution();
}); });
$("#saveCourse").click(function(){
});
$("#rateMyProf").click(function(){
window.open(rmpLink);
});
}); });
@@ -50,9 +53,11 @@ function getCourseInfo(row){
coursename = $(this).find('td').text() + ""; coursename = $(this).find('td').text() + "";
} }
if($(this).is(row)){ if($(this).is(row)){
profurl = $(this).find('td a').prop('href'); profurl = $(this).find('td[data-th="Unique"] a').prop('href');
profname = $(this).find('td').eq(4).text().split(', ')[0]; profname = $(this).find('td[data-th="Instructor"]').text().split(', ')[0];
profinit = $(this).find('td').eq(4).text().split(',')[1]; profinit = $(this).find('td[data-th="Instructor"]').text().split(',')[1];
//COME BACK AND FINISH
console.log($(this).find('td[data-th="Days"] >span').text());
return false; return false;
} }
}); });
@@ -101,12 +106,6 @@ function openDialog(dep,cls,sem,professor,res){
span.onclick = function() { span.onclick = function() {
modal.style.display = "none"; modal.style.display = "none";
} }
$("#saveCourse").click(function(){
});
$("#rateMyProf").click(function(){
window.open(rmpLink);
});
chart = Highcharts.chart('chart', { chart = Highcharts.chart('chart', {
chart: { chart: {
type: 'column', type: 'column',
@@ -212,7 +211,7 @@ function getDescription(){
$(".description").animate({'opacity': 0}, 400, function(){ $(".description").animate({'opacity': 0}, 400, function(){
$(this).html(description).animate({'opacity': 1}, 300); $(this).html(description).animate({'opacity': 1}, 300);
}); });
var first = object.find('td').eq(4).text(); var first = object.find('td[data-th="Instructor"]').text();
first = first.substring(first.indexOf(", "),first.indexOf(" ",first.indexOf(", ")+2)); first = first.substring(first.indexOf(", "),first.indexOf(" ",first.indexOf(", ")+2));
first = first.substring(2); first = first.substring(2);
rmpLink = "http://www.ratemyprofessors.com/search.jsp?queryBy=teacherName&schoolName=university+of+texas+at+austin&queryoption=HEADER&query="+first+" "+profname+";&facetSearch=true"; rmpLink = "http://www.ratemyprofessors.com/search.jsp?queryBy=teacherName&schoolName=university+of+texas+at+austin&queryoption=HEADER&query="+first+" "+profname+";&facetSearch=true";

BIN
icons/icon128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
icons/icon16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
icons/icon32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
icons/icon48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -5,10 +5,12 @@
"version": "0.1.0", "version": "0.1.0",
"description": "Chrome Extension to show more information on the UT Course catalog", "description": "Chrome Extension to show more information on the UT Course catalog",
"permissions": [ "permissions": [
"declarativeContent",
"storage",
"*://*.utdirect.utexas.edu/apps/registrar/course_schedule/*", "*://*.utdirect.utexas.edu/apps/registrar/course_schedule/*",
"*://*.ratemyprofessors.com/*", "*://*.ratemyprofessors.com/*",
"*://*.catalog.utexas.edu/ribbit/" "*://*.catalog.utexas.edu/ribbit/"
], ],
"content_scripts": [{ "content_scripts": [{
"css": ["styles.css"], "css": ["styles.css"],
"js": ["sql-memory-growth.js","highcharts.js","jquery-3.3.1.min.js","content.js"], "js": ["sql-memory-growth.js","highcharts.js","jquery-3.3.1.min.js","content.js"],
@@ -16,9 +18,23 @@
}], }],
"web_accessible_resources": [ "web_accessible_resources": [
"grades.db","disticon.png"], "grades.db","disticon.png"],
"background": { "background": {
"scripts": ["background.js"], "scripts": ["background.js"],
"persistent": true "persistent": true
},
"browser_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}
},
"icons": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
} }
} }

15
popup.html Normal file
View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<style>
button {
height: 30px;
width: 30px;
outline: none;
}
</style>
</head>
<body>
<button id="changeColor"></button>
</body>
</html>