Skip to content

Commit

Permalink
Merge pull request #9 from dnhuan/main
Browse files Browse the repository at this point in the history
To Release
  • Loading branch information
dnhuan authored Nov 1, 2023
2 parents 68e9f82 + 0a8a445 commit 92a479e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 83 deletions.
106 changes: 29 additions & 77 deletions src/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ function addRMPCol() {
.text("RMP");
$(".instructor.class-results-header-cell").after(placeholderHeader);
}
$(".class-results-cell.rmp").remove();
let placeholder = $("<div>")
.addClass("class-results-cell")
.addClass("rmp")
.text("Loading reviews...");
$(".instructor.class-results-cell").after(placeholder);

let tableRows = $(".course");
for (row of tableRows) {
Expand All @@ -89,13 +83,23 @@ function addRMPCol() {
function processResultTable() {
let allRows = $(".class-accordion");
for (row of allRows) {
// if class rmp cell does not exist, create it and append to row, after instructor cell
if ($(row).children(".rmp").length == 0) {
let placeholder = $("<div>")
.addClass("class-results-cell")
.addClass("rmp")
.text("Loading reviews...");
$(row).children(".instructor").after(placeholder.clone());
}
processCurrentRow(row);
}
}

async function processCurrentRow(row) {
let instructorDiv = $(row).children(".instructor").first();
if (instructorDiv.text().includes("Staff")) {
$(row).children(".rmp").empty();

$(row).children(".rmp").first().text("N/A");
return;
}
Expand All @@ -116,15 +120,13 @@ async function processCurrentRow(row) {

//check if comma is neccessary
const currentIndex = profReviewList.indexOf(profReview);
hasNext = profReviewList[currentIndex + 1] !== undefined && profReviewList[currentIndex + 1] !== null;

hasNext =
profReviewList[currentIndex + 1] !== undefined &&
profReviewList[currentIndex + 1] !== null;

// Insert score into DOM
//let HydratedProfScoreComp = ProfScoreComp(profReview);
let HydratedProfScoreComp = ProfReviewComp(profReview, hasNext);
$(row).children(".rmp").first().append(HydratedProfScoreComp);

// Decorate profName
//decorateInstructorDiv(instructorDiv, profReview);
}
}

Expand Down Expand Up @@ -156,68 +158,10 @@ async function getReview(profName) {
return profReview;
}

function decorateInstructorDiv(instructorDiv, profData) {
if (profData.numRatings == 0) {
return;
}

let colorCode = "";
if (profData.avgRating < 2.5) {
colorCode = "#FF9C9C";
} else if (profData.avgRating < 3.5) {
colorCode = "#FFFF68";
} else {
colorCode = "#68FFBE";
}

if (instructorDiv.children("span").length == 0) {
// only one prof
if (instructorDiv.text() === profData.name) {
instructorDiv
.children("a")
.first()
.css("background-color", colorCode);
}
}

let nameSpanList = instructorDiv.children("span").first().children("a");
for (nameSpan of nameSpanList) {
let name = $(nameSpan).text();
if (name === profData.name) {
$(nameSpan).css("background-color", colorCode);
}
}
}

function ProfScoreComp(profData) {
if (profData.numRatings == 0) {
return `<a style="color:#0F0F0F;text-decoration:none;" target="_blank" href="https://www.ratemyprofessors.com/ShowRatings.jsp?tid=${profData.legacyId}">N/A</a>`;
}

let colorCode = "";
if (profData.avgRating < 2.5) {
colorCode = "#FF9C9C";
} else if (profData.avgRating < 3.5) {
colorCode = "#FFFF68";
} else {
colorCode = "#68FFBE";
}
const divFormat = `
<div style="width:2.4rem;padding:2px;background-color:${colorCode}">
<a style="color:#0F0F0F;width:100%;text-decoration:none;" target="_blank" href="https://www.ratemyprofessors.com/ShowRatings.jsp?tid=${profData.legacyId}">
<span style="font-size:1rem">${profData.avgRating}</span>
<span style="float:right"><sup>/5</sup></span>
</a>
</div>`;

return divFormat;
}

function ProfReviewComp(profData, hasNext) {
if (profData.numRatings == 0) {
return `<a target="_blank" href="https://www.ratemyprofessors.com/ShowRatings.jsp?tid=${profData.legacyId}">N/A</a>`;
}
let colorFont = "#0F0F0F";
let colorCode = "";
if (profData.avgRating < 2.5) {
colorCode = "#FF9C9C";
Expand All @@ -227,21 +171,29 @@ function ProfReviewComp(profData, hasNext) {
colorCode = "#03C03C";
}

if(hasNext){
addComma = ", "
}else{
addComma = " "
if (hasNext) {
addComma = ", ";
} else {
addComma = " ";
}

const divFormat = `
<div class="prof-container">
<a style="text-decoration: none;" target="_blank" href="https://www.ratemyprofessors.com/ShowRatings.jsp?tid=${profData.legacyId}">
<a style="text-decoration: none;" target="_blank" href="https://www.ratemyprofessors.com/ShowRatings.jsp?tid=${
profData.legacyId
}">
<div>
<span class="prof-anchor" style="color:${colorCode}; font-size:1.5em; font-weight: bold;">${profData.avgRating}</span><span style="color:black;">${addComma}</span>
<span class="prof-anchor" style="color:${colorCode}; font-size:1.5em; font-weight: bold;">${
profData.avgRating
}</span><span style="color:black;">${addComma}</span>
</div>
</a>
<div class="prof-info" >
<div class="prof-namebox">${profData.name} <span style="color:${colorCode}; font-weight: bold;">${profData.avgRating}</span>/5</div>
<div class="prof-namebox">${
profData.name
} <span style="color:${colorCode}; font-weight: bold;">${
profData.avgRating
}</span>/5</div>
<div>${profData.avgDifficulty} difficulty</div>
<div>${profData.wouldTakeAgainPercent.toFixed(0)}% would take again</div>
<div>${profData.numRatings} rating(s)</div>
Expand Down
21 changes: 15 additions & 6 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
{
"name": "Rate My ASU Professors",
"version": "2.1.0",
"version": "2.2.0",
"description": "Rate My Professors Plugin for ASU Class Search. Allowing you to directly view professor ratings on the ASU Class Search page.",
"author": "[email protected]",
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["https://catalog.apps.asu.edu/*"],
"css": ["content/styles.css"]
"matches": [
"https://catalog.apps.asu.edu/*"
],
"css": [
"content/styles.css"
]
},
{
"matches": ["https://*.asu.edu/catalog/classes*"],
"matches": [
"https://*.asu.edu/catalog/classes*"
],
"js": [
"content/jquery-3.5.1.min.js",
"content/string-similarity.min.js",
"content/content.js"
]
}
],
"permissions": ["activeTab", "background"],
"permissions": [
"activeTab",
"background"
],
"host_permissions": [
"https://*.asu.edu/*",
"https://www.ratemyprofessors.com/*"
Expand All @@ -32,4 +41,4 @@
"128": "icon128.png"
},
"manifest_version": 3
}
}

0 comments on commit 92a479e

Please sign in to comment.