// ==UserScript==
// @name Show Rottentomatoes meter - Trakt UI Addon
// @description This is an addon script for "Show Rottentomatoes meter" by cuzi, that displays the Rottentomatoes info cleanly on the trakt.tv infobar
// @namespace 1N07
// @author 1N07
// @license MIT
// @icon https://cdn.jsdelivr.net/gh/OneNot/Userscripts@5461d4fda44160715de147a70e2adc9b37c0dd50/Show%20Rottentomatoes%20meter%20-%20Trakt%20UI%20Addon/logo.png
// @version 48.1.1
// @match https://trakt.tv/movies/*
// @match https://trakt.tv/shows/*
// @require https://cdn.jsdelivr.net/gh/OneNot/Userscripts@5461d4fda44160715de147a70e2adc9b37c0dd50/Libraries/WaitForKeyElement/index.min.js
// @downloadURL none
// ==/UserScript==
const HideRottenTomatoesMeterPanel = true;
function ApplyHideRottenTomatoesMeterPanelCSS() {
const style = document.createElement("style");
style.innerHTML = `
#mcdiv321rotten {
display: none;
}
`;
document.head.appendChild(style);
}
const RottentomatoesIcons = {
empty_tomato: ``,
empty_popcorn: ``,
red_popcorn: ``,
green_popcorn: ``,
rotten: ``,
fresh: ``,
certified_fresh: ``,
};
const GetRottenTomatoesScoreElement = (data) => {
const li = document.createElement("li");
li.className = "rtm-ui-" + data.type;
li.innerHTML = `
${data.icon}
${data.score}%
${data.type} score
`;
return li;
};
//TODO: error handling
//TODO: placeholders before load
(async () => {
if (HideRottenTomatoesMeterPanel) {
ApplyHideRottenTomatoesMeterPanelCSS();
}
WaitForKeyElement(`
.shows.show #summary-ratings-wrapper .ratings,
.movies.show #summary-ratings-wrapper .ratings
`).then((insertLocation) => {
WaitForKeyElement("#mcdiv321rotten > .firstResult").then((rottenEl) => {
const criticsTitle = rottenEl
.querySelector("[title^='Critics']")
.getAttribute("title");
const link = rottenEl.getElementsByTagName("a")[0].getAttribute("href");
const critics = criticsTitle?.length
? {
type: "Critics",
score: criticsTitle.split("Critics ")[1].split("%")[0],
icon: RottentomatoesIcons[
criticsTitle.split("% ")[1].split(/\s/)[0]
],
title: criticsTitle,
link: link,
}
: null;
const audienceTitle = rottenEl
.querySelector("[title^='Audience']")
.getAttribute("title");
const audience = audienceTitle?.length
? {
type: "Audience",
score: audienceTitle.split("Audience ")[1].split("%")[0],
icon: RottentomatoesIcons[
audienceTitle.split("% ")[1].split(/\s/)[0]
],
title: audienceTitle,
link: link,
}
: null;
insertLocation.appendChild(GetRottenTomatoesScoreElement(critics));
insertLocation.appendChild(GetRottenTomatoesScoreElement(audience));
});
});
})();