Skip to content

Commit

Permalink
update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin committed Oct 30, 2023
1 parent 7423c9f commit 77b30f2
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 17 deletions.
49 changes: 32 additions & 17 deletions src/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,25 @@ async function processCurrentRow(row) {
);
log(profReviewList);
$(row).children(".rmp").empty();

let hasNext = false;
for (profReview of profReviewList) {
if (profReview === null) {
$(row).children(".rmp").first().append($("<p>").text("N/A"));
continue;
}

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

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

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

Expand Down Expand Up @@ -206,7 +213,7 @@ function ProfScoreComp(profData) {
return divFormat;
}

function ProfReviewComp(profData) {
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>`;
}
Expand All @@ -215,24 +222,32 @@ function ProfReviewComp(profData) {
if (profData.avgRating < 2.5) {
colorCode = "#FF9C9C";
} else if (profData.avgRating < 3.5) {
colorCode = "#FFFF68";
colorCode = "#FFD700";
} else {
colorCode = "#68FFBE";
colorCode = "#03C03C";
}

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

const divFormat = `
<div style="background-color:${colorCode}">
<a style="color:${colorFont}" target="_blank" href="https://www.ratemyprofessors.com/ShowRatings.jsp?tid=${
profData.legacyId
}">
<div><span style="font-size:2em;font-weight: bold;">${
profData.avgRating
}</span>/5
</div>
<div>Average difficulty: ${profData.avgDifficulty}</div>
<div>${profData.wouldTakeAgainPercent.toFixed(0)}% would take again</div>
<div>${profData.numRatings} rating(s)</div>
<div class="prof-container">
<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>
</div>
</a>
</div>`;
<div class="prof-info" >
<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>
</div>
</div>
`;

return divFormat;
}
Expand Down
44 changes: 44 additions & 0 deletions src/content/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,47 @@
padding-left: 10px;
}
}


.prof-container {
position: relative;
display: inline-block;
}

.prof-info {
margin-left: 15px;
padding: 10px;
position: absolute;
top: 0;
left: 100%;
opacity: 0;
background-color: white;
transition: opacity .4s ease;
pointer-events: none;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
border-radius: 5px;
font-family: 'Arial', sans-serif;
width: 180px;
height: auto;

}

.prof-container:hover .prof-info {
background-color: white;
transition: opacity .4s ease;
opacity: 1;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
z-index: 1;
}

.prof-container:hover .prof-anchor {
background-color: rgba(246, 243, 243, 0.995);
}

.prof-namebox{
margin-bottom: 3px;
padding: 2px;
padding-left: 4px;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
border-radius: 5px;
}

0 comments on commit 77b30f2

Please sign in to comment.