Skip to content

Commit

Permalink
lowVoteCount
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamlinerm committed Oct 8, 2024
1 parent a62d9f6 commit cccce93
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions firefox/skipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,19 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
}
function useDBCache(title, card) {
if (!DBCache[title]?.date) DBCache[title].date = today;
const diffInReleaseDate = getDiffInDays(DBCache[title]?.release_date, date) <= 7 && getDiffInDays(DBCache[title].date, date) > 0;
// refresh rating if older than 30 days or release date is within 7 days
const vote_count = DBCache[title]?.vote_count || 100;
const diffInReleaseDate =
// vote count is under 80 accurate rating
vote_count < 100 &&
// did not refresh rating in the last 2 days
getDiffInDays(DBCache[title].date, date) > 2 &&
// release date is in the last 30 days after not many people will
getDiffInDays(DBCache[title]?.release_date, date) <= 50;

// refresh rating if older than 30 days or release date is in last month and vote count is under 100
if (getDiffInDays(DBCache[title].date, date) >= 30 || diffInReleaseDate) {
if (diffInReleaseDate) log("update recent movie:", title, ",Age:", getDiffInDays(DBCache[title]?.release_date, date));
if (diffInReleaseDate)
log("update recent movie:", title, ",Age:", getDiffInDays(DBCache[title]?.release_date, date), "Vote count:", vote_count);
else log("update old rating:", title, ",Age:", getDiffInDays(DBCache[title].date, date));
getMovieInfo(title, card);
// log("no info today", title);
Expand Down Expand Up @@ -378,7 +387,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
?.split(" – ")[0]
?.split(", ")[0]
?.replace(/(S\d+)/g, "")
?.replace(/ \[dt\.?\/OV\]/g, "")
?.replace(/ \[dt\.\/?O?V?\]/g, "")
?.replace(/\[OV\]/g, "")
?.replace(/\s\(.*\)/g, "")
?.replace(/:?\sStaffel-?\s\d+/g, "")
Expand All @@ -396,7 +405,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
// sometimes more than one image is loaded for the same title
if (title && lastTitle != title && !title.includes("Netflix") && !title.includes("Prime Video")) {
lastTitle = title;
if (DBCache[title]?.score || getDiffInDays(DBCache[title]?.date, date) <= 1) {
if (DBCache[title]?.score || getDiffInDays(DBCache[title]?.date, date) <= 7) {
useDBCache(title, card);
} else {
getMovieInfo(title, card);
Expand All @@ -412,32 +421,33 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
}, 5000);
}
}
function getColorForRating(rating) {
function getColorForRating(rating, lowVoteCount) {
// I want a color gradient from red to green with yellow in the middle
// the ratings are between 0 and 10
// the average rating is 6.5
// https://distributionofthings.com/imdb-movie-ratings/
if (!rating) return "grey";
if (!rating || lowVoteCount) return "grey";
if (rating <= 5.5) return "red";
if (rating <= 7) return "rgb(245, 197, 24)"; //#f5c518
return "rgb(0, 166, 0)";
}

async function setRatingOnCard(card, data, title) {
let div = document.createElement("div");
const vote_count = data?.vote_count || 100;
// right: 1.5vw;
div.style =
"position: absolute;bottom: 0;right:0;z-index: 9999;color: black;background:" +
getColorForRating(data?.score) +
getColorForRating(data?.score, vote_count <= 50) +
";border-radius: 5px;padding: 0 2px 0 2px;" +
(isMobile ? "font-size: 4vw;" : "font-size: 1vw;");
// div.id = "imdb";
if (data?.score) {
if (data?.score && vote_count > 50) {
div.textContent = data.score?.toFixed(1);
div.setAttribute("alt", data?.title + ", OG title: " + title);
div.setAttribute("alt", data?.title + ", OG title: " + title + ", Vote count: " + vote_count);
} else if (data?.title) {
div.textContent = "N/A";
div.setAttribute("alt", data?.title + ", OG title: " + title);
div.setAttribute("alt", data?.title + ", OG title: " + title + ", Vote count: " + vote_count);
} else {
div.textContent = "?";
div.setAttribute("alt", title);
Expand Down

0 comments on commit cccce93

Please sign in to comment.