Skip to content

Commit

Permalink
refactiring and updated to handle new ratemyprofs catgories and layout
Browse files Browse the repository at this point in the history
  • Loading branch information
demetrios-koziris committed May 25, 2016
1 parent 6c6b4f2 commit d6ad505
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
49 changes: 25 additions & 24 deletions js/courseLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ function encodeSymbolsWin1252(string) {
return encodeURI(string).replace("%C3%8", "%C").replace("%C3%9", "%D").replace("%C3%A", "%E").replace("%C3%B", "%F").replace("'", "%27");
}

function updateProfURL(profKey, profURL) {
profElements = document.getElementsByClassName(profKey);
for (var p = 0; p < profElements.length; p++) {
profElements[p].href = profURL;
}
}


function getProfUrl(profName, general) {

var profURL = "http://www.ratemyprofessors.com/search.jsp?query=mcgill " + profName.firstName + " " + profName.lastName + " " ;
Expand All @@ -40,7 +48,7 @@ function getProfUrl(profName, general) {
getProfContent(profName, profURL, 0);
}
else {
profURL = getProfUrl(profName, true);
getProfUrl(profName, true);
}
}
else if (listings.length == 1) {
Expand All @@ -60,6 +68,8 @@ function getProfUrl(profName, general) {


function getProfContent(profName, profURL, res) {
updateProfURL(profName.fullNameKey, profURL)

var xmlRequestInfo = {
method: 'GET',
action: 'xhttp',
Expand All @@ -74,10 +84,8 @@ function getProfContent(profName, profURL, res) {

var rating = {
overall: -1,
helpfulness: -1,
clarity: -1,
easiness: -1,
grade: -1,
difficulty: -1,
takeagain: -1,
hotness: -1
}

Expand All @@ -97,15 +105,11 @@ function getProfContent(profName, profURL, res) {
else {

gradeElements = htmlDoc.getElementsByClassName("grade");
ratingElements = htmlDoc.getElementsByClassName("rating")


rating.overall = gradeElements[0].innerHTML
rating.helpfulness = ratingElements[0].innerHTML
rating.clarity = ratingElements[1].innerHTML
rating.easiness = ratingElements[2].innerHTML
rating.grade = gradeElements[1].innerHTML

rating.hotness = gradeElements[2].innerHTML
rating.takeagain = gradeElements[1].innerHTML
rating.difficulty = gradeElements[2].innerHTML
rating.hotness = gradeElements[3].innerHTML
if (rating.hotness != undefined) {
rating.hotness = rating.hotness.match(/chilis\/(.+)\-chili\.png/)[1];
}
Expand All @@ -114,15 +118,13 @@ function getProfContent(profName, profURL, res) {
lastName = htmlDoc.getElementsByClassName("plname")[0].innerHTML.trim();

tooltipContent = "<b>" + firstName + " " + lastName + "</b>"
+ "<br><b>" + rating.overall + "&nbsp Overall Quality</b>"
+ "<br>" + rating.helpfulness + "&nbsp Helpfulness"
+ "<br>" + rating.clarity + "&nbsp Clarity"
+ "<br>" + rating.easiness + "&nbsp Easiness"
+ "<br><b>" + rating.overall + "</b>&nbsp Overall Quality"
+ "<br><b>" + rating.difficulty + "</b>&nbsp Level Of Difficulty"
+ "<br><b>" + rating.takeagain + "</b>&nbsp Would Take Again"

numOfRatings = htmlDoc.getElementsByClassName("rating-count")[0].innerHTML.match(/([0-9]+) Student Ratings/)[1]
tooltipContent += "<br><b>From " + numOfRatings + " student rating" + (numOfRatings > 1 ? "s" : "") + "</b>"
+ "<br>Rater Ave Grade: " + rating.grade + "&nbsp"
+ "<br>Prof Hotness: " + rating.hotness.toUpperCase() + "&nbsp"
tooltipContent += "<br>From <b>" + numOfRatings + " student rating" + (numOfRatings > 1 ? "s" : "") + "</b>"
+ "<br>Prof Hotness: <b>" + rating.hotness.toUpperCase() + "</b>&nbsp"
}
}
makeProfSection(profName, profURL, tooltipContent);
Expand All @@ -138,7 +140,6 @@ function makeProfSection(profName, profURL, tooltipContent) {

profElements = document.getElementsByClassName(profName.fullNameKey);
for (var p = 0; p < profElements.length; p++) {
profElements[p].href = profURL;
profElements[p].title = tooltipContent;
}

Expand Down Expand Up @@ -264,7 +265,7 @@ if (url.match(/.+study.+courses.+[-]+/) != null) {
}

profs[profName.firstName+profName.lastName] = profName;
newProfsHTML += ("<a href='http://www.ratemyprofessors.com' class=\"tooltip " + profName.fullNameKey + "\" title=\"" + loadMessage + "\">" + profName.fullName + "</a>");
newProfsHTML += ("<a href='http://www.ratemyprofessors.com/search.jsp?query=mcgill " + profName.firstName + " " + profName.lastName + " ' class=\"tooltip " + profName.fullNameKey + "\" title=\"" + loadMessage + "\">" + profName.fullName + "</a>");
if (p <= profsF.length-2) {
newProfsHTML += ", "
}
Expand Down Expand Up @@ -294,7 +295,7 @@ if (url.match(/.+study.+courses.+[-]+/) != null) {
}

profs[profName.firstName+profName.lastName] = profName;
newProfsHTML += ("<a href='http://www.ratemyprofessors.com' class=\"tooltip " + profName.fullNameKey + "\" title=\"" + loadMessage + "\">" + profName.fullName + "</a>");
newProfsHTML += ("<a href='http://www.ratemyprofessors.com/search.jsp?query=mcgill " + profName.firstName + " " + profName.lastName + " ' class=\"tooltip " + profName.fullNameKey + "\" title=\"" + loadMessage + "\">" + profName.fullName + "</a>");
if (p <= profsW.length-2) {
newProfsHTML += ", "
}
Expand Down Expand Up @@ -324,7 +325,7 @@ if (url.match(/.+study.+courses.+[-]+/) != null) {
}

profs[profName.firstName+profName.lastName] = profName;
newProfsHTML += ("<a href='http://www.ratemyprofessors.com' class=\"tooltip " + profName.fullNameKey + "\" title=\"" + loadMessage + "\">" + profName.fullName + "</a>");
newProfsHTML += ("<a href='http://www.ratemyprofessors.com/search.jsp?query=mcgill " + profName.firstName + " " + profName.lastName + " ' class=\"tooltip " + profName.fullNameKey + "\" title=\"" + loadMessage + "\">" + profName.fullName + "</a>");

if (p <= profsS.length-2) {
newProfsHTML += ", "
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "McGill Enhanced",
"manifest_version": 2,
"version": "2.1.35",
"version": "2.1.36",
"description": "Enhance the functionality of McGill.ca",
"permissions" : [
"declarativeContent"
Expand Down

0 comments on commit d6ad505

Please sign in to comment.