diff --git a/src/content/content.js b/src/content/content.js index 47aa4db..5a12447 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -73,12 +73,6 @@ function addRMPCol() { .text("RMP"); $(".instructor.class-results-header-cell").after(placeholderHeader); } - $(".class-results-cell.rmp").remove(); - let placeholder = $("
") - .addClass("class-results-cell") - .addClass("rmp") - .text("Loading reviews..."); - $(".instructor.class-results-cell").after(placeholder); let tableRows = $(".course"); for (row of tableRows) { @@ -89,6 +83,14 @@ 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 = $("
") + .addClass("class-results-cell") + .addClass("rmp") + .text("Loading reviews..."); + $(row).children(".instructor").after(placeholder.clone()); + } processCurrentRow(row); } } @@ -96,6 +98,8 @@ function processResultTable() { 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; } @@ -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); } } @@ -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 `N/A`; - } - - let colorCode = ""; - if (profData.avgRating < 2.5) { - colorCode = "#FF9C9C"; - } else if (profData.avgRating < 3.5) { - colorCode = "#FFFF68"; - } else { - colorCode = "#68FFBE"; - } - const divFormat = ` -
- - ${profData.avgRating} - /5 - -
`; - - return divFormat; -} - function ProfReviewComp(profData, hasNext) { if (profData.numRatings == 0) { return `N/A`; } - let colorFont = "#0F0F0F"; let colorCode = ""; if (profData.avgRating < 2.5) { colorCode = "#FF9C9C"; @@ -227,21 +171,29 @@ function ProfReviewComp(profData, hasNext) { colorCode = "#03C03C"; } - if(hasNext){ - addComma = ", " - }else{ - addComma = " " + if (hasNext) { + addComma = ", "; + } else { + addComma = " "; } const divFormat = `
- +
- ${profData.avgRating}${addComma} + ${ + profData.avgRating + }${addComma}
-
${profData.name} ${profData.avgRating}/5
+
${ + profData.name + } ${ + profData.avgRating + }/5
${profData.avgDifficulty} difficulty
${profData.wouldTakeAgainPercent.toFixed(0)}% would take again
${profData.numRatings} rating(s)
diff --git a/src/manifest.json b/src/manifest.json index 44776c9..8eb65bb 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,6 +1,6 @@ { "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": "huan@huandoan.tech", "background": { @@ -8,11 +8,17 @@ }, "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", @@ -20,7 +26,10 @@ ] } ], - "permissions": ["activeTab", "background"], + "permissions": [ + "activeTab", + "background" + ], "host_permissions": [ "https://*.asu.edu/*", "https://www.ratemyprofessors.com/*" @@ -32,4 +41,4 @@ "128": "icon128.png" }, "manifest_version": 3 -} +} \ No newline at end of file