TMDB with IMDB, Letterboxd, RottenTomatoes, Metacritic & MyAnimeList ratings

It adds IMDB, RottenTomatoes, Metacritic, MyAnimeList & Awards/Nominations to TMDB

  1. // ==UserScript==
  2. // @name TMDB with IMDB, Letterboxd, RottenTomatoes, Metacritic & MyAnimeList ratings
  3. // @description It adds IMDB, RottenTomatoes, Metacritic, MyAnimeList & Awards/Nominations to TMDB
  4. // @match https://www.themoviedb.org/*
  5. // @version 2.16.13
  6. // @author SH3LL
  7. // @grant GM_xmlhttpRequest
  8. // @grant GM_getResourceText
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @namespace https://greasyfork.org/users/762057
  12. // @resource RT_api https://pastebin.com/raw/NXHeK6nf
  13. // @connect algolia.net
  14. // @connect rottentomatoes.com
  15. // @connect themoviedb.org
  16. // ==/UserScript==
  17.  
  18. // Helpers
  19.  
  20. function clean_t(title){
  21. if(title===null||title===undefined) return "";
  22. return title.toLowerCase()
  23. .replace("The Motion Picture","")
  24. .replace("The Movie","").replace("Movie","")
  25. .replaceAll(/[$&+,:;=?@#|'<>.^*()%!"-]+/g,'') //remove all special characters
  26. .replaceAll(/\s\s+/g,'') //remove multipla spaces
  27. .trim()
  28. }
  29.  
  30. function asyncGet (url, options = {}) {
  31. if (options.params) {
  32. url = url + '?' + $.param(options.params)
  33. }
  34.  
  35. const id = options.title || url
  36. const request = Object.assign({ method: 'GET', url }, options.request || {})
  37. return new Promise((resolve, reject) => {
  38. request.onload = res => {
  39. if (res.status >= 400) {
  40. console.log(res);
  41. const error = Object.assign(
  42. new Error(`error fetching ${id} (${res.status} ${res.statusText})`),
  43. { status: res.status, statusText: res.statusText }
  44. )
  45.  
  46. reject(error)
  47. } else {
  48. resolve(res)
  49. }
  50. }
  51.  
  52. // XXX apart from +finalUrl+, the +onerror+ response object doesn't
  53. // contain any useful info
  54. request.onerror = _res => {
  55. const { status, statusText } = CONNECTION_ERROR
  56. const error = Object.assign(
  57. new Error(`error fetching ${id} (${status} ${statusText})`),
  58. { status, statusText },
  59. )
  60.  
  61. reject(error)
  62. }
  63.  
  64. GM_xmlhttpRequest(request)
  65. })
  66. }
  67.  
  68. // Functions
  69.  
  70. function TMDB_search_api(TMDB_id,content) {
  71.  
  72. if (content==="movie"){
  73. return new Promise(function (resolve, reject) {
  74. GM_xmlhttpRequest({
  75. method: 'GET',
  76. responseType: 'json',
  77. synchronous: false,
  78. url: 'https://api.themoviedb.org/3/movie/'+TMDB_id+'?api_key=8d6d91941230817f7807d643736e8a49&language=en&append_to_response=external_ids,keywords',
  79. onload: (resp) => {
  80.  
  81. let json = JSON.parse(resp.responseText);
  82. console.log('TMDB title api: https://api.themoviedb.org/3/movie/'+TMDB_id+'?api_key=8d6d91941230817f7807d643736e8a49&language=en&append_to_response=external_ids,keywords');
  83.  
  84. if (json && json.Error) {
  85. console.log("Error: " + json.Error);
  86. resolve("error"); return;
  87.  
  88. }
  89.  
  90. let IMDB_id=0,TMDB_title=0, TMDB_original_title=0, TMDB_year=0,anime_flag=0;
  91.  
  92. if(json.title!==undefined && json.title!==null) TMDB_title = json.title;
  93. if(json.original_title!==undefined && json.original_title!==null) TMDB_original_title = json.original_title;
  94. if(json.external_ids!==undefined && json.external_ids.imdb_id!== null) IMDB_id = json.external_ids.imdb_id;
  95. if(json.release_date!==null && json.release_date!==undefined) TMDB_year=json.release_date.slice(0,4);
  96. if(json.keywords!==undefined && json.keywords.keywords!==undefined && json.keywords.keywords!==null){
  97. for(let keyword of json.keywords.keywords){
  98. if(keyword.name==="anime"){anime_flag=1; break;}
  99. }
  100. }
  101. resolve([TMDB_title,TMDB_original_title,TMDB_year,IMDB_id,anime_flag]); return;
  102.  
  103. }
  104. });
  105. });
  106.  
  107. }else if(content==="tv"){
  108. return new Promise(function (resolve, reject) {
  109. GM_xmlhttpRequest({
  110. method: 'GET',
  111. responseType: 'json',
  112. synchronous: false,
  113. url: 'https://api.themoviedb.org/3/tv/'+TMDB_id+'?api_key=8d6d91941230817f7807d643736e8a49&language=en&append_to_response=external_ids,keywords',
  114. onload: (resp) => {
  115.  
  116. let json = JSON.parse(resp.responseText);
  117. console.log('TMDB title api: https://api.themoviedb.org/3/tv/'+TMDB_id+'?api_key=8d6d91941230817f7807d643736e8a49&language=en&append_to_response=external_ids,keywords');
  118.  
  119. if (json && json.Error) {
  120. console.log("Error: " + json.Error);
  121. resolve("error"); return;
  122.  
  123. }
  124.  
  125. let IMDB_id=0,TMDB_title=0, TMDB_original_title=0,seasons_count=0,anime_flag=0;
  126.  
  127. if(json.name!==undefined && json.name!==null) TMDB_title = json.name;
  128. if(json.original_name!==undefined && json.original_name!==null) TMDB_original_title = json.original_name;
  129. if(json.external_ids!==undefined && json.external_ids.imdb_id!== null) IMDB_id = json.external_ids.imdb_id; //imdb id
  130. if(json.seasons!==undefined && json.seasons!== null) seasons_count = (json.seasons).length;
  131. if(json.keywords!==undefined && json.keywords.results!==undefined && json.keywords.results!==null){
  132. for(let keyword of json.keywords.results){
  133. if(keyword.name==="anime"){anime_flag=1; break;}
  134. }
  135. }
  136.  
  137. //years range
  138. let first_year="N/A",last_year="N/A",years_range;
  139.  
  140. if(json.first_air_date!==undefined && json.first_air_date!==null) first_year = json.first_air_date.slice(0,4);
  141. if(json.last_air_date!==undefined && json.last_air_date!==null) {
  142. if(json.last_air_date.slice(2,4) !== first_year.slice(2,4)) last_year = json.last_air_date.slice(2,4);
  143. }
  144.  
  145. if(last_year !=="N/A") years_range=first_year + "-" + last_year; else years_range=first_year;
  146.  
  147. resolve([TMDB_title,TMDB_original_title,first_year,years_range,IMDB_id,seasons_count,anime_flag]); return;
  148.  
  149. }
  150. });
  151. });
  152. }
  153. }
  154.  
  155. function IMDB_info_scrape(IMDB_id) {
  156. return new Promise(function (resolve, reject) {
  157. GM_xmlhttpRequest({
  158. method: 'GET',
  159. responseType: 'document',
  160. synchronous: false,
  161. url: "https://www.imdb.com/title/"+IMDB_id,
  162. onload: (resp) => {
  163. const doc = document.implementation.createHTMLDocument().documentElement;
  164. doc.innerHTML = resp.responseText;
  165. console.log("IMDB link: "+"https://www.imdb.com/title/"+IMDB_id)
  166.  
  167. let IMDB_rating=0, IMDB_votes_number=0, IMDB_awards=0, IMDB_next_title=0,IMDB_next_date=0;
  168. if(doc.querySelectorAll('.sc-acdbf0f3-3')[0]!=undefined){
  169. IMDB_rating = doc.querySelectorAll('.sc-d541859f-1')[0].innerText;
  170. IMDB_votes_number = doc.querySelectorAll('.sc-d541859f-3')[0].innerText;
  171. let awards_hook=doc.querySelectorAll('.sc-aa5ab255-0');
  172. if(awards_hook.length!==0) IMDB_awards = awards_hook[0].children[1].children[0].children[0].innerText + ". "+awards_hook[0].children[1].children[0].children[1].innerText;
  173. if(IMDB_awards===undefined) IMDB_awards=0;
  174. }
  175. resolve([IMDB_rating,IMDB_votes_number,IMDB_awards]); return;
  176. }
  177. });
  178. })
  179. }
  180.  
  181. function LB_search_scrape(title,year) {
  182. return new Promise(function (resolve, reject) {
  183. GM_xmlhttpRequest({
  184. method: 'GET',
  185. responseType: 'json',
  186. synchronous: false,
  187. url: 'https://letterboxd.com/search/films/'+title.replaceAll(" ", "+"),
  188. onload: (resp) => {
  189.  
  190. console.log("LT link: "+ 'https://letterboxd.com/search/films/'+title.replaceAll(" ", "+"));
  191.  
  192. const doc = document.implementation.createHTMLDocument().documentElement;
  193. doc.innerHTML = resp.responseText;
  194.  
  195. let results = doc.getElementsByClassName("film-detail-content");
  196. for(let curr_movie of results){
  197. let curr_title = clean_t(curr_movie.children[0].children[0].children[0].innerText);
  198. let curr_year = clean_t(curr_movie.children[0].children[0].children[1].innerText);
  199. let curr_url = "https://letterboxd.com"+curr_movie.children[0].children[0].children[0].href;
  200.  
  201. console.log("LB title: "+title)
  202. console.log("LB year: "+year)
  203. console.log("LB url: "+curr_url)
  204.  
  205. if( ( parseInt(curr_year) === parseInt(year) && clean_t(curr_title) === clean_t(title) ) ||
  206. ( (parseInt(curr_year) === parseInt(year) + 1 || parseInt(curr_year) === parseInt(year) -1 )&& clean_t(curr_title) === clean_t(title) )
  207. ){
  208. resolve(curr_url); return;
  209. }
  210.  
  211. }
  212.  
  213. resolve("error"); return;
  214. }
  215. });
  216. });
  217. }
  218.  
  219. function LB_info_scrape(LB_url){
  220. let LB_score_url=LB_url.replace("/film/","/csi/film/")+"rating-histogram/"
  221. return new Promise(function (resolve, reject) {
  222. GM_xmlhttpRequest({
  223. method: 'GET',
  224. responseType: 'document',
  225. synchronous: false,
  226. url: LB_score_url,
  227. onload: (resp) => {
  228. const doc = document.implementation.createHTMLDocument().documentElement;
  229. doc.innerHTML = resp.responseText;
  230. console.log("Scraping LB scores: "+LB_score_url)
  231.  
  232. let LB_score=0,LB_users=0;
  233.  
  234. if(doc.getElementsByClassName("average-rating")[0]!=undefined){
  235. let LB_score_sentence = doc.getElementsByClassName("average-rating")[0].children[0].getAttribute("title");
  236. LB_score=LB_score_sentence.split("based on")[0].replace("Weighted average of ","").trim();
  237. LB_users=LB_score_sentence.split("based on")[1].replace(" ratings","").trim();
  238. }
  239. resolve([LB_score,LB_users]); return;
  240. }
  241. });
  242. })
  243. }
  244.  
  245. function RT_search_scrape(title,year,content) {
  246. return new Promise(function (resolve, reject) {
  247. GM_xmlhttpRequest({
  248. method: 'GET',
  249. responseType: 'json',
  250. synchronous: false,
  251. url: 'https://www.rottentomatoes.com/search?search='+title.replaceAll(" ", "%20"),
  252. onload: (resp) => {
  253. if(content==="tv"){content="tvSeries";}
  254. console.log("RT link: "+ 'https://www.rottentomatoes.com/search?search='+title.replaceAll(" ", "%20"));
  255.  
  256. const doc = document.implementation.createHTMLDocument().documentElement;
  257. doc.innerHTML = resp.responseText;
  258.  
  259. let Search_Sections = doc.getElementsByTagName("search-page-result");
  260. for(let myelement of Search_Sections){
  261.  
  262. if(myelement.getAttribute("type")===content){
  263.  
  264. let titles = myelement.getElementsByTagName("ul")[0];
  265.  
  266. for(let current_title of titles.children){
  267. // get year
  268. let curr_year = current_title.getAttribute("releaseyear");
  269. if (curr_year==="") curr_year = current_title.getAttribute("startyear");
  270.  
  271. // get title name and link
  272. let title_link_node = current_title.getElementsByTagName("a")[1];
  273. let curr_title=title_link_node.innerText;
  274. let curr_RT_url = title_link_node.href; if(curr_RT_url===undefined || curr_RT_url===null){continue;}
  275.  
  276. if( ( parseInt(curr_year) === parseInt(year) && clean_t(curr_title) === clean_t(title) ) ||
  277. ( (parseInt(curr_year) === parseInt(year) + 1 || parseInt(curr_year) === parseInt(year) -1 )&& clean_t(curr_title) === clean_t(title) )
  278. ){
  279. resolve(curr_RT_url); return;
  280. }
  281.  
  282. }
  283.  
  284. }
  285.  
  286. }
  287.  
  288. resolve("error"); return;
  289. }
  290. });
  291. });
  292. }
  293.  
  294. function RT_search_api(title,year,content) {
  295.  
  296. return new Promise(async function (resolve, reject) {
  297.  
  298. // build request payload
  299. const template = GM_getResourceText('RT_api');
  300. const query = JSON.stringify(clean_t(title));
  301. let typeId; if(content==="movie"){typeId="1"}; if(content==="tv"){typeId="2"};
  302. const json = template.replace('{{typeId}}', String(typeId)).replace('{{apiLimit}}', String(100));
  303. const { api, params, data } = JSON.parse(json);
  304. for (const [key, value] of Object.entries(params)) {
  305. if (value && typeof value === 'object') {
  306. params[key] = JSON.stringify(value)
  307. }
  308. }
  309.  
  310. // add title to request
  311. Object.assign(data.requests[0], {
  312. query,
  313. params: $.param(params),
  314. })
  315.  
  316. // final request
  317. const apiRequest = {
  318. title: 'API',
  319. request: {
  320. data: JSON.stringify(data),
  321. method: 'POST',
  322. responseType: 'json',
  323. },
  324. }
  325.  
  326. //send request
  327. let res = await asyncGet(api, apiRequest);
  328.  
  329. console.log(res.responseText); //output the api response
  330.  
  331. let json_output = JSON.parse(res.responseText);
  332. let delta=0;
  333. for(let curr_result of json_output.results[0].hits){
  334. let curr_title = curr_result.title;
  335. let curr_year = curr_result.releaseYear;
  336.  
  337. console.log("RT search api: [" + clean_t(curr_title)+"]"+"["+clean_t(title)+"]");
  338.  
  339. if(parseInt(curr_year) === parseInt(year) && clean_t(curr_title) === clean_t(title)){ //fix rotten tomatoes errors
  340. delta=curr_result.vanity; break;
  341. }/*else if(( parseInt(curr_year) === parseInt(year) + 1 || parseInt(curr_year) === parseInt(year) -1 )&& clean_t(curr_title) === clean_t(title)){
  342. delta=curr_result.vanity; break;
  343. }else if(parseInt(curr_year) === parseInt(year) && clean_t(curr_title).includes(clean_t(title))){
  344. delta=curr_result.vanity; break;
  345. }else if(( parseInt(curr_year) === parseInt(year) + 1 || parseInt(curr_year) === parseInt(year) -1 )&& clean_t(curr_title).includes(clean_t(title))){
  346. delta=curr_result.vanity; break;
  347. }*/
  348.  
  349. if(curr_result.aka != undefined){
  350. for(let curr_aka_title of curr_result.aka){
  351. console.log("RT search AKA api: [" + clean_t(curr_aka_title)+"]"+"["+clean_t(title)+"]");
  352. if(clean_t(curr_aka_title) === clean_t(title) && parseInt(curr_year) === parseInt(year)){ //fix rotten tomatoes errors
  353. delta=curr_result.vanity; break;
  354. }/*else if(( parseInt(curr_year) === parseInt(year) + 1 || parseInt(curr_year) === parseInt(year) -1 )&& clean_t(curr_title) === clean_t(title)){
  355. delta=curr_result.vanity; break;
  356. }else if(parseInt(curr_year) === parseInt(year) && clean_t(curr_title).includes(clean_t(title))){
  357. delta=curr_result.vanity; break;
  358. }else if(( parseInt(curr_year) === parseInt(year) + 1 || parseInt(curr_year) === parseInt(year) -1 )&& clean_t(curr_title).includes(clean_t(title))){
  359. delta=curr_result.vanity; break;
  360. }*/
  361. }
  362. }
  363.  
  364. }
  365. if (content==="movie"){
  366. resolve("https://www.rottentomatoes.com/m/"+delta);
  367. }else if(content==="tv"){
  368. resolve("https://www.rottentomatoes.com/tv/"+delta);
  369. }
  370. });
  371. }
  372.  
  373. function RT_info_scrape(RT_url){
  374. return new Promise(function (resolve, reject) {
  375. GM_xmlhttpRequest({
  376. method: 'GET',
  377. responseType: 'document',
  378. synchronous: false,
  379. url: RT_url,
  380. onload: (resp) => {
  381. const doc = document.implementation.createHTMLDocument().documentElement;
  382. doc.innerHTML = resp.responseText;
  383. console.log("Scraping RT: "+RT_url)
  384.  
  385. let tomatometer_score=0, tomatometer_state=0, audience_score=0,audience_state=0,tomatometer_icon_box=0,tomatometer_score_box=0,audience_icon_box=0,audience_score_box=0;
  386. let all_scores_box=0;
  387.  
  388. if(doc.querySelector("score-board-deprecated")!==undefined) all_scores_box=doc.querySelector("score-board-deprecated");
  389. console.log(all_scores_box);
  390.  
  391. if(all_scores_box!==undefined && all_scores_box!==null){
  392. tomatometer_score = all_scores_box.getAttributeNode('tomatometerscore').value==="" ? 0 : all_scores_box.getAttributeNode('tomatometerscore').value;
  393. tomatometer_state = all_scores_box.getAttributeNode('tomatometerstate').value==="" ? 0 : all_scores_box.getAttributeNode('tomatometerstate').value;
  394. audience_score = all_scores_box.getAttributeNode('audiencescore').value==="" ? 0 : all_scores_box.getAttributeNode('audiencescore').value;
  395. audience_state = all_scores_box.getAttributeNode('audiencestate').value==="" ? 0 : all_scores_box.getAttributeNode('audiencestate').value;
  396.  
  397. console.log(tomatometer_score+"-"+tomatometer_state+"-"+audience_score+"-"+audience_state)
  398.  
  399. }else{
  400. if(doc.querySelector("media-scorecard")!==undefined) all_scores_box=doc.querySelector("media-scorecard");
  401. console.log(all_scores_box)
  402. tomatometer_score = all_scores_box.querySelector('rt-text[slot="criticsScore"]') == undefined ? 0 : all_scores_box.querySelector('rt-text[slot="criticsScore"]').innerText.replace("%","").trim();
  403. tomatometer_state = all_scores_box.querySelector('score-icon-critics') == undefined ? 0 : all_scores_box.querySelector('score-icon-critics').getAttribute('certified');
  404. if(tomatometer_state=="false"){tomatometer_state = all_scores_box.querySelector('score-icon-critics') == undefined ? 0 : all_scores_box.querySelector('score-icon-critics').getAttribute('sentiment');}
  405. audience_score = all_scores_box.querySelector('rt-text[slot="audienceScore"]') == undefined ? 0: all_scores_box.querySelector('rt-text[slot="audienceScore"]').innerText.replace("%","").trim();
  406. audience_state = all_scores_box.querySelector('score-icon-audience') == undefined ? 0 : all_scores_box.querySelector('score-icon-audience').getAttribute('sentiment');
  407. if(tomatometer_state=="POSITIVE"){
  408. tomatometer_state = "fresh";
  409. }else if(tomatometer_state=="NEGATIVE"){
  410. tomatometer_state = "rotten";
  411. }else if(tomatometer_state=="true"){
  412. tomatometer_state = "certified-fresh";
  413. }else{tomatometer_state=0;}
  414.  
  415. if(audience_state=="POSITIVE"){
  416. audience_state = "upright";
  417. }else if(audience_state=="NEGATIVE"){
  418. audience_state = "spilled";
  419. }else{audience_state=0;}
  420.  
  421. /*let scoreboxes = doc.getElementsByClassName("mop-ratings-wrap__half");
  422.  
  423. if(scoreboxes.length===0){resolve([0,0,0,0]); return;}
  424. let tomatometer_box=scoreboxes[0]; let audience_box=scoreboxes[1];
  425.  
  426. if(tomatometer_box.getElementsByClassName("mop-ratings-wrap__icon")!==undefined) tomatometer_icon_box = tomatometer_box.getElementsByClassName("mop-ratings-wrap__icon")[0]; tomatometer_score_box = tomatometer_box.getElementsByClassName("mop-ratings-wrap__percentage")[0];
  427. if(audience_box.getElementsByClassName("mop-ratings-wrap__icon")!==undefined) audience_icon_box = audience_box.getElementsByClassName("mop-ratings-wrap__icon")[0]; audience_score_box = audience_box.getElementsByClassName("mop-ratings-wrap__percentage")[0];
  428.  
  429. if(tomatometer_icon_box!==undefined){
  430. if(tomatometer_icon_box.className.includes("rotten")) tomatometer_state="rotten";
  431. if(tomatometer_icon_box.className.includes("certified-fresh")) tomatometer_state="certified-fresh";
  432. if(tomatometer_icon_box.className.includes("fresh")) tomatometer_state="fresh";
  433. tomatometer_score=tomatometer_score_box.innerText.trim().replaceAll("%","");
  434. }
  435. if(audience_icon_box!==undefined){
  436. if(audience_icon_box.className.includes("upright")) audience_state="upright";
  437. if(audience_icon_box.className.includes("spilled")) audience_state="spilled";
  438. audience_score=audience_score_box.innerText.trim().replaceAll("%","");
  439. }
  440. */
  441.  
  442.  
  443. }
  444. resolve([tomatometer_score,tomatometer_state,audience_score,audience_state]); return;
  445. }
  446. });
  447. })
  448. }
  449.  
  450. function MC_search_scrape(title,year,content,sort) { // title= ORIGINAL->movies, TITLE->anime
  451. if (content==="movie"){
  452.  
  453. return new Promise(function (resolve, reject) {
  454. GM_xmlhttpRequest({
  455. method: 'GET',
  456. responseType: 'document',
  457. synchronous: false,
  458. url: "https://www.metacritic.com/search/"+title+"/?page=1&category=2"+"&sortBy="+sort,
  459. onload: async (resp) => {
  460. const doc = document.implementation.createHTMLDocument().documentElement;
  461. doc.innerHTML = resp.responseText;
  462. console.log("MC link: "+"https://www.metacritic.com/search/"+title.replaceAll(" ", "%20")+"/?page=1&category=2"+"&sortBy="+sort,)
  463.  
  464. let result_list = doc.getElementsByClassName('g-grid-container u-grid-columns');
  465. if (result_list!==undefined){
  466. for (let curr_el of result_list){
  467. let curr_title=0,curr_title_link=0,curr_rating=0,curr_year=0;
  468.  
  469. if(curr_el.getElementsByClassName('g-text-medium-fluid g-text-bold g-outer-spacing-bottom-small u-text-overflow-ellipsis')[0]===undefined) continue;
  470.  
  471. if(curr_el.getElementsByClassName('g-text-medium-fluid g-text-bold g-outer-spacing-bottom-small u-text-overflow-ellipsis')[0]!=undefined) curr_title = curr_el.getElementsByClassName('g-text-medium-fluid g-text-bold g-outer-spacing-bottom-small u-text-overflow-ellipsis')[0].innerText.trim();
  472. curr_title_link = "https://www.metacritic.com/"+content+"/"+clean_t(curr_title).replaceAll(" ","-")
  473. if(curr_el.getElementsByClassName('c-siteReviewScore_background c-siteReviewScore_background-critic_medium')[0]!=undefined) curr_rating = curr_el.getElementsByClassName('c-siteReviewScore_background c-siteReviewScore_background-critic_medium')[0].innerText.trim();
  474. if(curr_el.getElementsByClassName('u-flexbox u-flexbox-alignCenter u-flexbox-nowrap g-gap-medium g-text-xxxsmall')[0].getElementsByClassName("u-text-overflow-ellipsis")[0]!=undefined) curr_year = curr_el.getElementsByClassName('u-flexbox u-flexbox-alignCenter u-flexbox-nowrap g-gap-medium g-text-xxxsmall')[0].getElementsByClassName("u-text-overflow-ellipsis")[0].innerText.trim();
  475. console.log("MC title:"+ curr_title);
  476. console.log("MC link:"+curr_title_link);
  477. console.log("MC rating:"+curr_rating);
  478. console.log("MC year:"+curr_year);
  479.  
  480. if(clean_t(curr_title)===clean_t(title) && ( parseInt(curr_year)===parseInt(year) || parseInt(curr_year)+1===parseInt(year) || parseInt(curr_year)-1===parseInt(year) )){
  481. let MC_info = await MC_info_scrape(curr_title_link);
  482. resolve([MC_info[0],MC_info[1],MC_info[2],MC_info[3],MC_info[4],curr_title_link]); return;
  483.  
  484. }
  485. }
  486.  
  487.  
  488. }
  489. resolve("error"); return;
  490. }
  491. });
  492. })
  493.  
  494.  
  495. }else if(content==="tv"){
  496.  
  497. return new Promise(function (resolve, reject) {
  498. GM_xmlhttpRequest({
  499. method: 'GET',
  500. responseType: 'document',
  501. synchronous: false,
  502. url: "https://www.metacritic.com/search/"+title+"/?page=1&category=1"+"&sortBy="+sort,
  503. onload: async (resp) => {
  504. const doc = document.implementation.createHTMLDocument().documentElement;
  505. doc.innerHTML = resp.responseText;
  506. console.log("MC link: "+"https://www.metacritic.com/search/"+title.replaceAll(" ", "%20")+"/?page=1&category=1"+"&sortBy="+sort)
  507.  
  508. let result_list = doc.getElementsByClassName('g-grid-container u-grid-columns');
  509. if (result_list!==undefined){
  510. for (let curr_el of result_list){
  511. let curr_title=0,curr_title_link=0,curr_rating=0,curr_year=0;
  512.  
  513. if(curr_el.getElementsByClassName('g-text-medium-fluid g-text-bold g-outer-spacing-bottom-small u-text-overflow-ellipsis')[0]===undefined) continue;
  514.  
  515. if(curr_el.getElementsByClassName('g-text-medium-fluid g-text-bold g-outer-spacing-bottom-small u-text-overflow-ellipsis')[0]!=undefined) curr_title = curr_el.getElementsByClassName('g-text-medium-fluid g-text-bold g-outer-spacing-bottom-small u-text-overflow-ellipsis')[0].innerText.trim();
  516. curr_title_link = "https://www.metacritic.com/"+content+"/"+clean_t(curr_title).replaceAll(" ","-")
  517. if(curr_el.getElementsByClassName('c-siteReviewScore_background c-siteReviewScore_background-critic_medium')[0]!=undefined) curr_rating = curr_el.getElementsByClassName('c-siteReviewScore_background c-siteReviewScore_background-critic_medium')[0].innerText.trim();
  518. if(curr_el.getElementsByClassName('u-flexbox u-flexbox-alignCenter u-flexbox-nowrap g-gap-medium g-text-xxxsmall')[0].getElementsByClassName("u-text-overflow-ellipsis")[0]!=undefined) curr_year = curr_el.getElementsByClassName('u-flexbox u-flexbox-alignCenter u-flexbox-nowrap g-gap-medium g-text-xxxsmall')[0].getElementsByClassName("u-text-overflow-ellipsis")[0].innerText.trim();
  519. console.log("MC title:"+ curr_title);
  520. console.log("MC link:"+curr_title_link);
  521. console.log("MC rating:"+curr_rating);
  522. console.log("MC year:"+curr_year);
  523.  
  524. if(clean_t(curr_title)===clean_t(title) && ( parseInt(curr_year)===parseInt(year) || parseInt(curr_year)+1===parseInt(year) || parseInt(curr_year)-1===parseInt(year) )){
  525. let MC_info = await MC_info_scrape(curr_title_link);
  526. resolve([MC_info[0],MC_info[1],MC_info[2],MC_info[3],MC_info[4],curr_title_link]); return;
  527.  
  528. }
  529. }
  530.  
  531.  
  532. }
  533. resolve("error"); return;
  534. }
  535. });
  536. })
  537.  
  538. }
  539. }
  540.  
  541. function MC_info_scrape(link){
  542. return new Promise(function (resolve, reject) {
  543. GM_xmlhttpRequest({
  544. method: 'GET',
  545. responseType: 'document',
  546. synchronous: false,
  547. url: link,
  548. onload: (resp) => {
  549. const doc = document.implementation.createHTMLDocument().documentElement;
  550. doc.innerHTML = resp.responseText;
  551.  
  552. let MC_MetaScore=0, MC_UserScore=0, MC_Critics=0, MC_Users=0,MC_must_see=0;
  553.  
  554. // Get number of critics and users
  555. let stats_blocks = doc.getElementsByClassName("c-productScoreInfo_scoreContent u-flexbox u-flexbox-alignCenter u-flexbox-justifyFlexEnd g-width-100 u-flexbox-nowrap");
  556. if(stats_blocks[0]!=undefined && stats_blocks[1]!=undefined && stats_blocks[0].innerText.includes("Metascore")) {
  557. if(stats_blocks[0].getElementsByClassName("c-productScoreInfo_reviewsTotal u-block")[0]!=undefined) MC_Critics = stats_blocks[0].getElementsByClassName("c-productScoreInfo_reviewsTotal u-block")[0].innerText
  558. if(stats_blocks[0].getElementsByClassName("c-productScoreInfo_scoreNumber u-float-right")[0]!=undefined) MC_MetaScore = stats_blocks[0].getElementsByClassName("c-productScoreInfo_scoreNumber u-float-right")[0].innerText.trim();
  559. if(stats_blocks[1].getElementsByClassName("c-productScoreInfo_reviewsTotal u-block")[0]!=undefined) MC_Users = stats_blocks[1].getElementsByClassName("c-productScoreInfo_reviewsTotal u-block")[0].innerText
  560. if(stats_blocks[1].getElementsByClassName("c-productScoreInfo_scoreNumber u-float-right")[0]!=undefined) MC_UserScore = stats_blocks[1].getElementsByClassName("c-productScoreInfo_scoreNumber u-float-right")[0].innerText.trim();
  561. }else if(stats_blocks[0]!=undefined && stats_blocks[1]!=undefined){
  562. if(stats_blocks[1].getElementsByClassName("c-productScoreInfo_reviewsTotal u-block")[0]!=undefined) MC_Critics = stats_blocks[1].getElementsByClassName("c-productScoreInfo_reviewsTotal u-block")[0].innerText
  563. if(stats_blocks[1].getElementsByClassName("c-productScoreInfo_scoreNumber u-float-right")[0]!=undefined) MC_MetaScore = stats_blocks[1].getElementsByClassName("c-productScoreInfo_scoreNumber u-float-right")[0].innerText.trim();
  564. if(stats_blocks[0].getElementsByClassName("c-productScoreInfo_reviewsTotal u-block")[0]!=undefined) MC_Users = stats_blocks[0].getElementsByClassName("c-productScoreInfo_reviewsTotal u-block")[0].innerText
  565. if(stats_blocks[0].getElementsByClassName("c-productScoreInfo_scoreNumber u-float-right")[0]!=undefined) MC_UserScore = stats_blocks[0].getElementsByClassName("c-productScoreInfo_scoreNumber u-float-right")[0].innerText.trim();
  566. }
  567. // Fix Strings
  568. if(MC_Critics!==undefined && MC_Critics!==0 && MC_Critics!=="tbd"){MC_Critics=MC_Critics.replace(/[^0-9]/g,'').trim();}else{MC_Critics="n/a"}
  569. if(MC_Users!==undefined && MC_Users!==0 && MC_Users!=="tbd"){MC_Users=MC_Users.replace(/[^0-9]/g,'').trim();}else{MC_Users="n/a"}
  570. if(MC_MetaScore!==undefined && MC_MetaScore!==0 && MC_MetaScore!=="tbd"){MC_MetaScore=MC_MetaScore.replace(/[^0-9]/g,'').trim();}else{MC_MetaScore="n/a"}
  571. if(MC_UserScore!==undefined && MC_UserScore!==0 && MC_UserScore!=="tbd"){MC_UserScore=MC_UserScore.replace(/[^0-9]/g,'').trim();}else{MC_UserScore="n/a"}
  572. // Get MustSee Tag
  573. if(doc.querySelector('img[src="https://www.metacritic.com/a/neutron/images/logos/badge/must-see.png"]')!==undefined && doc.querySelector('img[src="https://www.metacritic.com/a/neutron/images/logos/badge/must-see.png"]')!==null) MC_must_see=1;
  574. resolve([MC_MetaScore,MC_Critics,MC_UserScore,MC_Users,MC_must_see]); return;
  575. }
  576. });
  577. })
  578. }
  579.  
  580. function JIKAN_search_api(title,original_title,year,content) {
  581.  
  582. if (content==="movie"){
  583. return new Promise(function (resolve, reject) {
  584. GM_xmlhttpRequest({
  585. method: 'GET',
  586. responseType: 'json',
  587. synchronous: false,
  588. url: 'https://api.jikan.moe/v4/anime?q='+original_title.replaceAll(" ","%20")+'&page=1',
  589. onload: (resp) => {
  590. let json = JSON.parse(resp.responseText);
  591. console.log('MAL search api: https://api.jikan.moe/v4/anime?q='+original_title.replaceAll(" ","%20")+'&page=1');
  592.  
  593. if (json.data==undefined || json.Error) {
  594. console.log("Error: " + json.Error);
  595. resolve("error"); return;
  596.  
  597. }
  598.  
  599. let MAL_url=0, MAL_title_name=0, MAL_score=0, content_type=0, episodes_count=0, start_date=0;
  600. for(let result of json.data){
  601.  
  602. console.log("[JIKAN en:"+result.title_english+"] - [JIKAN:"+result.title+"] - [TMDB:"+title+"]");
  603.  
  604. if(result.aired.from!== null) console.log("JIKAN year:"+result.aired.from.slice(0,4)+" ||||| TMDB year:"+year)
  605.  
  606. if( result.type!==null && result.aired.from!==null &&
  607. (parseInt(result.aired.from.slice(0,4))===parseInt(year) || parseInt(result.aired.from.slice(0,4))===parseInt(year)-1 || parseInt(result.aired.from.slice(0,4))===parseInt(year)-2) &&
  608. (result.type === "Movie" /*TV*/ || result.type === "ONA" || result.type === "OVA") &&
  609. ( clean_t(result.title_english) === clean_t(title) ||
  610. clean_t(result.title_japanese) === clean_t(title) ||
  611. clean_t(result.title) === clean_t(title) ||
  612. clean_t(result.title_english) === clean_t(original_title) ||
  613. clean_t(result.title_japanese) === clean_t(original_title) ||
  614. clean_t(result.title) === clean_t(original_title)
  615. )){
  616.  
  617. if(result.url!== null) MAL_url = result.url;
  618. if(result.score!== null) MAL_score = result.score;
  619. if(result.episodes!== null) episodes_count = result.episodes;
  620. if(result.aired.from!== null) start_date = result.aired.from.slice(0,4);
  621.  
  622. resolve([MAL_url, MAL_score, episodes_count, start_date]); return;
  623. }
  624. }
  625. console.log("JIKAN [MAL]: Error, title not found");
  626. resolve("error"); return;
  627.  
  628. }
  629. });
  630. });
  631.  
  632. }else if(content==="tv"){
  633. return new Promise(function (resolve, reject) {
  634. GM_xmlhttpRequest({
  635. method: 'GET',
  636. responseType: 'json',
  637. synchronous: false,
  638. url: 'https://api.jikan.moe/v4/anime?q='+original_title.replaceAll(" ","%20")+'&page=1&limit=10',
  639. onload: (resp) => {
  640.  
  641. let json = JSON.parse(resp.responseText);
  642. console.log('MAL search api: https://api.jikan.moe/v4/anime?q='+original_title.replaceAll(" ","%20")+'&page=1&limit=10');
  643.  
  644. if (json.data==undefined || json.Error) {
  645. console.log("Error: " + json.Error);
  646. resolve("error"); return;
  647.  
  648. }
  649.  
  650. let MAL_url=0, MAL_score=0, episodes_count=0, start_date=0, end_date=0, date_range=0;
  651. for(let result of json.data){
  652.  
  653. console.log("[JIKAN en:"+result.title_english+"] - [JIKAN:"+result.title+"] - [TMDB:"+title+"]");
  654.  
  655. if(result.type!==null && result.aired.from!==null &&
  656. (parseInt(result.aired.from.slice(0,4))===parseInt(year) || parseInt(result.aired.from.slice(0,4))===parseInt(year)-1 || parseInt(result.aired.from.slice(0,4))===parseInt(year)-2) &&
  657. (result.type === "TV" || result.type === "ONA" || result.type === "OVA") &&
  658. ( clean_t(result.title_english) === clean_t(title) ||
  659. clean_t(result.title_japanese) === clean_t(title) ||
  660. clean_t(result.title) === clean_t(title) ||
  661. clean_t(result.title_english) === clean_t(original_title) ||
  662. clean_t(result.title_japanese) === clean_t(original_title) ||
  663. clean_t(result.title) === clean_t(original_title)
  664. )){
  665.  
  666. if(result.url!== null) MAL_url = result.url;
  667. if(result.score!== null) MAL_score = result.score;
  668. if(result.episodes!== null) episodes_count = result.episodes;
  669. if(result.aired.from!== null) start_date = result.aired.from.slice(0,4);
  670. if(result.aired.to!== null) end_date = result.aired.to.slice(2,4);
  671.  
  672. if(start_date!== 0 && end_date!== 0) date_range = start_date + "-" + end_date
  673.  
  674. resolve([MAL_url, MAL_score, episodes_count, date_range]); return;
  675. }
  676. }
  677.  
  678. console.log("JIKAN [MAL]: Error, title not found");
  679. resolve("error"); return;
  680.  
  681. }
  682. });
  683. });
  684. }
  685. }
  686.  
  687. async function main(){
  688. let content=0;
  689. let TMDB_info=0, TMDB_id=0, TMDB_title=0, TMDB_original_title=0, TMDB_year=0, tv_year_range=0, seasons_count=0;
  690. let IMDB_info, IMDB_id=0, IMDB_score=0, IMDB_votes_number=0,IMDB_awards=0;
  691. let RT_scraped_info=0, RT_url=0, RT_audience_state=0, RT_audience_score=0, RT_tomatometer_state=0, RT_tomatometer_score=0;
  692. let LB_scraped_info=0,LB_score=0,LB_users=0;
  693. let MAL_info=0, MAL_url=0, MAL_score=0, episodecount=0, MAL_year=0, anime_flag=0;
  694. let MC_info=0, MC_MetaScore=0,MC_Critics=0,MC_UserScore=0,MC_Users=0,MC_url=0,MC_must_see=0;
  695. let YT_trailer_delta=0;
  696.  
  697. //get youtube link
  698. let YT_button = document.getElementsByClassName("no_click play_trailer")[0];
  699. if(YT_button!==undefined && YT_button!==null) YT_trailer_delta=YT_button.getAttribute("data-id");
  700. console.log("Grabbed Youtube Delta: "+YT_trailer_delta);
  701. //Remove bloats
  702. $(".tooltip").remove();
  703. $(".play_trailer").remove();
  704. $("#vibes_label").remove();
  705. $(".consensus_reaction_items").remove();
  706.  
  707. //Hook per appendere i punteggi dei providers
  708. let page_score_icon = document.getElementsByClassName("chart");
  709. let loading_div = document.createElement("div");
  710. let loading_label = document.createElement("label");
  711. loading_label.innerText="⏳ Loading Results.."
  712. loading_label.style.color="firebrick";
  713. loading_div.style.paddingRight="20px";
  714. loading_div.append(loading_label);
  715.  
  716. page_score_icon[0].after(loading_div);
  717.  
  718. //Grab TMDB ID
  719. if(window.location.href.includes("https://www.themoviedb.org/movie/")){
  720. content="movie";
  721. TMDB_id = parseInt(window.location.href.split("https://www.themoviedb.org/movie/")[1].split("-")[0]);
  722. }else if(window.location.href.includes("https://www.themoviedb.org/tv/")){
  723. content="tv";
  724. TMDB_id = parseInt(window.location.href.split("https://www.themoviedb.org/tv/")[1].split("-")[0]);
  725. }else{return;}
  726.  
  727. //Get TMDB title info
  728. TMDB_info = await TMDB_search_api(TMDB_id,content);
  729. if(content==="movie"){
  730. TMDB_title=TMDB_info[0];
  731. TMDB_original_title=TMDB_info[1];
  732. TMDB_year=TMDB_info[2];
  733. IMDB_id=TMDB_info[3];
  734. if(parseInt(TMDB_info[4])===1) anime_flag="movie";
  735. }else if(content==="tv"){
  736. TMDB_title=TMDB_info[0];
  737. TMDB_original_title=TMDB_info[1];
  738. TMDB_year=TMDB_info[2];
  739. tv_year_range=TMDB_info[3];
  740. IMDB_id=TMDB_info[4];
  741. seasons_count=TMDB_info[5];
  742. if(parseInt(TMDB_info[6])===1) anime_flag="tv";
  743. }
  744.  
  745. //Get IMDB score
  746. if(IMDB_id!==0 && IMDB_id!=="error") IMDB_info = await IMDB_info_scrape(IMDB_id);
  747. if(IMDB_info!=="error" && IMDB_info!==0){
  748. if(IMDB_info[0]!=0){IMDB_score=IMDB_info[0];}else{IMDB_score="N/A"}
  749. if(IMDB_info[1]!=0){IMDB_votes_number=IMDB_info[1];}else{IMDB_votes_number="N/A"}
  750. IMDB_awards=IMDB_info[2];
  751. }
  752.  
  753. //Get RT score
  754. //if(TMDB_title!==0) RT_url = await RT_search_scrape(TMDB_title,TMDB_year,content);
  755. console.log(TMDB_title+":"+TMDB_year);
  756. if(TMDB_title!==0) RT_url= await RT_search_api(TMDB_title,TMDB_year,content);
  757.  
  758. if(RT_url!=="error" && RT_url!==0){
  759.  
  760. RT_scraped_info = await RT_info_scrape(RT_url);
  761. RT_tomatometer_score=RT_scraped_info[0]; if(RT_tomatometer_score==0){RT_tomatometer_score="N/A"}
  762. RT_tomatometer_state=RT_scraped_info[1];
  763. RT_audience_score=RT_scraped_info[2]; if(RT_audience_score==0){RT_audience_score="N/A"}
  764. RT_audience_state=RT_scraped_info[3];
  765. }
  766.  
  767. //Get LB score
  768. if(content==="movie"){
  769.  
  770. if(TMDB_title!==0) LB_url= await LB_search_scrape(TMDB_title,TMDB_year);
  771. if(LB_url!=="error" && LB_url!==0){
  772.  
  773. LB_scraped_info = await LB_info_scrape(LB_url);
  774. LB_score=LB_scraped_info[0]; if(LB_score==0){LB_score="N/A"}
  775. LB_users=LB_scraped_info[1]; if(LB_users==0){LB_users="N/A"}
  776. }
  777.  
  778. }
  779.  
  780. //Get MAL score
  781. if(TMDB_title!==0 && anime_flag!==0) MAL_info = await JIKAN_search_api(TMDB_title,TMDB_original_title,TMDB_year,content);
  782. if(MAL_info!=="error" && MAL_info!==0 && anime_flag!==0){
  783. MAL_url=MAL_info[0];
  784. MAL_score=parseFloat(MAL_info[1]);
  785. if(Number.isInteger(MAL_score)){
  786. MAL_score = String(MAL_score)+".00"
  787. }else{
  788. let f_numbers = String(MAL_score).split(".")[1].length;
  789. if(f_numbers===1) MAL_score=MAL_score+"0";
  790. }
  791. episodecount=MAL_info[2];
  792. MAL_year=MAL_info[3];
  793. }
  794.  
  795. //Get MC score
  796. //console.log("TMDB_Title:"+TMDB_title+" | TMDB_Original_Title="+TMDB_original_title);
  797. if(TMDB_title!==0 ) MC_info = await MC_search_scrape(TMDB_title,TMDB_year,content,"");
  798. if(TMDB_title!==0 && (MC_info=="error" || MC_info==0)) MC_info = await MC_search_scrape(TMDB_title,TMDB_year,content,"META_SCORE");
  799. if(MC_info!=="error" && MC_info!==0){
  800. MC_MetaScore=MC_info[0];
  801. MC_Critics=MC_info[1];
  802. MC_UserScore=MC_info[2];
  803. MC_Users=MC_info[3];
  804. MC_must_see=MC_info[4];
  805. MC_url=MC_info[5];
  806. //console.log(MC_MetaScore+"-"+MC_Critics+"-"+MC_UserScore+"-"+MC_Users+"-"+MC_url+"- MustSee="+MC_must_see);
  807. }
  808.  
  809. //Build IMDB label
  810. let IMDB_image_link = document.createElement("a");
  811. let IMDB_image = document.createElement("img");
  812. let IMDB_image_div = document.createElement("div");
  813. let IMDB_link = document.createElement("a");
  814. let IMDB_link_div = document.createElement("div");
  815. let IMDB_label = document.createElement("label");
  816. let IMDB_div = document.createElement("div");
  817.  
  818. if(IMDB_info!=="error" && IMDB_info!==0){
  819. IMDB_image.src="https://i.postimg.cc/13Vp7gMQ/245px-IMDB-Logo-2016-svg.png"; IMDB_image.style.width="60px";
  820. IMDB_image_link.href="https://www.imdb.com/title/"+IMDB_id;
  821. IMDB_image_link.append(IMDB_image);
  822. IMDB_image_div.append(IMDB_image_link);
  823.  
  824. IMDB_link.href="https://www.imdb.com/title/"+IMDB_id+"/ratings"; IMDB_link.innerText=IMDB_score; IMDB_link.style.color="gold"; IMDB_link.style.fontWeight = 'bold'; IMDB_link.style.marginLeft="auto"; IMDB_link.style.marginRight="auto";
  825. IMDB_label.innerText="("+IMDB_votes_number+")"; IMDB_label.style.fontSize="50%"; IMDB_label.style.color="gold"; IMDB_label.style.paddingLeft="5px";
  826. IMDB_link_div.append(IMDB_link,IMDB_label);
  827.  
  828. IMDB_div.style.marginRight="13px"; IMDB_div.style.marginLeft="15px"; IMDB_div.style.width="60px"
  829. IMDB_div.append(IMDB_image_div,IMDB_link_div);
  830. }
  831.  
  832. //Build LB label
  833. let LB_image_link = document.createElement("a");
  834. let LB_image = document.createElement("img");
  835. let LB_image_div = document.createElement("div");
  836. let LB_link = document.createElement("a");
  837. let LB_link_div = document.createElement("div");
  838. let LB_label = document.createElement("label");
  839. let LB_div = document.createElement("div");
  840.  
  841. if(LB_scraped_info!=="error" && LB_scraped_info!==0){
  842. LB_image.src="https://i.postimg.cc/qRWTyVNV/letterbox.png"; LB_image.style.width="69px";LB_image.style.borderRadius = "3px";
  843. LB_image_link.href=LB_url;
  844. LB_image_link.append(LB_image);
  845. LB_image_div.append(LB_image_link);
  846.  
  847. LB_link.href=LB_url+"members"; LB_link.innerText=LB_score; LB_link.style.color="deepskyblue"; LB_link.style.fontWeight = 'bold'; LB_link.style.marginLeft="auto"; LB_link.style.marginRight="auto";
  848. LB_label.innerText="("+LB_users+")"; LB_label.style.fontSize="50%"; LB_label.style.color="deepskyblue"; LB_label.style.paddingLeft="5px";LB_label.style.marginRight="30px";
  849. LB_link_div.append(LB_link,LB_label);
  850.  
  851. LB_div.style.marginRight="28px"; LB_div.style.marginLeft="15px"; LB_div.style.width="60px"
  852. LB_div.append(LB_image_div,LB_link_div);
  853. }
  854.  
  855. //Build RT label
  856. let RT_image_link = document.createElement("a");
  857. let RT_image = document.createElement("img");
  858. let RT_image_critic = document.createElement("img");
  859. let RT_image_audience = document.createElement("img");
  860. let RT_image_div = document.createElement("div");
  861. let RT_link_critic = document.createElement("a");
  862. let RT_link_users = document.createElement("a");
  863. let RT_link_div = document.createElement("div");
  864. let RT_div = document.createElement("div");
  865.  
  866. if(RT_url!=="error" && RT_url!==0){
  867. if(RT_tomatometer_state==="certified-fresh") {RT_image.src="https://i.postimg.cc/MGvKmRY7/fresh-rotten.png"}else{RT_image.src="https://i.postimg.cc/YtNd2pYn/rotten-tomatoes-new-logo.png";} RT_image.style.borderRadius = "3px";
  868. RT_image.style.width="69px"; RT_image.style.marginRight="15px"; RT_image.style.marginLeft="5px"; if(RT_tomatometer_score==="100" || RT_audience_score==="100"){ RT_image.style.marginLeft="10px"}
  869. RT_image_link.href=RT_url;
  870. RT_image_link.append(RT_image);
  871. RT_image_div.append(RT_image_link);
  872.  
  873. RT_image_critic.style.width= RT_tomatometer_score===0 || RT_tomatometer_score==="N/A" ? "0px" : "12px"; RT_image_critic.style.display="inline"; RT_link_critic.style.paddingRight="5px"; RT_link_critic.style.paddingLeft="5px";
  874. RT_image_audience.style.width= RT_audience_score===0 || RT_audience_score==="N/A" ? "0px" : "12px"; RT_image_audience.style.display="inline"; RT_link_users.style.paddingRight="5px"; RT_link_users.style.paddingLeft="5px";
  875. if(RT_tomatometer_state==="fresh") RT_image_critic.src='https://i.postimg.cc/0xxLPX6n/fresh.png';
  876. if(RT_tomatometer_state==="certified-fresh") RT_image_critic.src='https://i.postimg.cc/FNmmCgXd/certified-fresh.png';
  877. if(RT_tomatometer_state==="rotten") RT_image_critic.src='https://i.postimg.cc/HW1HgbJN/rotten.png';
  878. if(RT_audience_state==="upright") RT_image_audience.src='https://i.postimg.cc/b81pRVWf/upright.png';
  879. if(RT_audience_state==="spilled") RT_image_audience.src='https://i.postimg.cc/2YsChNHx/spilled.png';
  880. RT_link_critic.href=RT_url+"/reviews";
  881. RT_link_critic.innerText= RT_tomatometer_score===0 ? "N/A" : RT_tomatometer_score ; RT_link_critic.style.color= RT_tomatometer_score===0 ? "grey" : "white"; RT_link_critic.style.fontWeight="bold";
  882. RT_link_users.href=RT_url+"/reviews?type=user";
  883. RT_link_users.innerText= RT_audience_score===0 ? "N/A" : RT_audience_score ; RT_link_users.style.color= RT_audience_score===0 ? "grey" : "white"; RT_link_users.style.fontWeight="bold";
  884. console.log(RT_image_critic)
  885. RT_link_div.append(RT_image_critic,RT_link_critic,RT_image_audience,RT_link_users); RT_link_div.style.paddingRight="15px";
  886.  
  887. RT_div.append(RT_image_div,RT_link_div);
  888. }
  889.  
  890. //Build MC Label
  891. let MC_image_link = document.createElement("a");
  892. let MC_image = document.createElement("img");
  893. let MC_image_div = document.createElement("div");
  894. let MC_critics_link = document.createElement("a");
  895. let MC_critics_label = document.createElement("label");
  896. let MC_users_link = document.createElement("a");
  897. let MC_users_label = document.createElement("label");
  898. let MC_scores_div = document.createElement("div");
  899. let MC_div = document.createElement("div");
  900.  
  901. if(MC_info!==0 && MC_info!=="error"){
  902. if(MC_must_see===1){MC_image.src="https://i.postimg.cc/QNKCWSTq/mc.png"}else{MC_image.src="https://i.postimg.cc/dtLsHFTJ/mc.png"}
  903. MC_image.style.width="69px"; MC_image.style.marginLeft="5px"; MC_image.style.borderRadius = "3px";
  904. MC_image_link.href=MC_url;
  905. MC_image_link.append(MC_image);
  906. MC_image_div.append(MC_image_link);
  907.  
  908. let compact_critics; if(parseInt(MC_Critics)>1000){compact_critics=String((MC_Critics/1000).toFixed(2)).slice(0,-1) + "k";}else{compact_critics=MC_Critics}
  909. let compact_users; if(parseInt(MC_Users)>1000){compact_users=String((MC_Users/1000).toFixed(2)).slice(0,-1) + "k";}else{compact_users=MC_Users}
  910. //critics
  911. MC_critics_link.innerText=MC_MetaScore; MC_critics_link.href=MC_url+"/critic-reviews"; MC_critics_link.style.fontWeight="bold"; MC_critics_link.style.paddingLeft="4px";
  912. if(!isNaN(MC_MetaScore) && MC_MetaScore<=39){MC_critics_link.style.color="red"; MC_critics_label.style.color=MC_critics_link.style.color;}
  913. else if(!isNaN(MC_MetaScore) && MC_MetaScore>=39 && MC_MetaScore<=60){MC_critics_link.style.color="burlywood"; MC_critics_label.style.color=MC_critics_link.style.color;}
  914. else if(!isNaN(MC_MetaScore) && MC_MetaScore>=61){MC_critics_link.style.color="greenyellow"; MC_critics_label.style.color=MC_critics_link.style.color;}
  915. else if(isNaN(MC_MetaScore)){MC_critics_link.style.color="grey"; MC_critics_label.style.color=MC_critics_link.style.color;}
  916. MC_critics_label.innerText=" ("+compact_critics+")"; MC_critics_label.style.fontSize="50%";
  917. //users
  918. MC_users_link.innerText=MC_UserScore; MC_users_link.href=MC_url+"/user-reviews"; MC_users_link.style.fontWeight="bold"; MC_users_link.style.paddingLeft="4px";
  919. if(!isNaN(MC_UserScore) && parseFloat(MC_UserScore)<=3.9){MC_users_link.style.color="red"; MC_users_label.style.color=MC_users_link.style.color;}
  920. else if(!isNaN(MC_UserScore) && parseFloat(MC_UserScore)>=3.9 && parseFloat(MC_UserScore)<=6.0){MC_users_link.style.color="burlywood"; MC_users_label.style.color=MC_users_link.style.color;}
  921. else if(!isNaN(MC_UserScore) && parseFloat(MC_UserScore)>=6.1){MC_users_link.style.color="greenyellow"; MC_users_label.style.color=MC_users_link.style.color;}
  922. else if(isNaN(MC_UserScore)){MC_users_link.style.color="grey"; MC_users_label.style.color=MC_users_link.style.color;}
  923. MC_users_label.innerText=" ("+compact_users+")"; MC_users_label.style.fontSize="50%";
  924. MC_scores_div.append(MC_critics_link,MC_critics_label,MC_users_link,MC_users_label);
  925.  
  926. MC_div.append(MC_image_div,MC_scores_div); MC_div.style.paddingRight="15px";
  927. }
  928.  
  929. //Build MAL Label
  930. let MAL_image_link = document.createElement("a");
  931. let MAL_image = document.createElement("img");
  932. let MAL_image_div = document.createElement("div");
  933. let MAL_link = document.createElement("a");
  934. let MAL_link_div = document.createElement("div");
  935. let MAL_div = document.createElement("div");
  936.  
  937. if(MAL_info!==0 && MAL_info!=="error"){
  938. MAL_image.src="https://i.postimg.cc/bwPmk7d2/apple-touch-icon-256.png"; MAL_image.style.width="30px"; MAL_image.style.borderRadius = '3px'
  939. MAL_image_link.href=MAL_url;
  940. MAL_image_link.append(MAL_image);
  941. MAL_image_div.append(MAL_image_link); MAL_image_div.style.paddingLeft="5px";
  942.  
  943. MAL_link.innerText=MAL_score; MAL_link.href=MAL_url+"/reviews"; MAL_link.style.color="cornflowerblue"; MAL_link.style.fontWeight="bold"; MAL_link.style.paddingLeft="4px";
  944. MAL_link_div.append(MAL_link);
  945.  
  946. MAL_div.append(MAL_image_div,MAL_link_div); MAL_div.style.paddingRight="15px";
  947. }
  948.  
  949. //Build YouTube Label
  950. let YT_image_link = document.createElement("a");
  951. let YT_image = document.createElement("img");
  952. let YT_image_div = document.createElement("div");
  953. let YT_link = document.createElement("a");
  954. let YT_link_div = document.createElement("div");
  955. let YT_div = document.createElement("div");
  956. if(TMDB_title!==0){
  957. YT_image.src="https://i.postimg.cc/CKGRZxLF/youtube-PNG102349.png"; YT_image.style.width="46px"; YT_image.style.paddingBottom="18px"; YT_image.style.borderRadius = '3px';
  958. if(YT_trailer_delta!==0 && YT_trailer_delta!==null && YT_trailer_delta!==undefined) {
  959. YT_image_link.href="https://www.youtube.com/watch?v="+YT_trailer_delta;
  960. }else{
  961. YT_image_link.href="https://www.youtube.com/results?search_query="+TMDB_title+" trailer";
  962. }
  963. YT_image_link.append(YT_image);
  964. YT_image_div.append(YT_image_link);
  965.  
  966. //YT_link.innerText="Trailer"; YT_link.href=YT_image_link.href; YT_link.style.color="red"; YT_link.style.fontSize="80%"; YT_link.style.marginLeft="4px";
  967. //YT_link_div.append(YT_link);
  968.  
  969. YT_div.append(YT_image_div); YT_div.style.paddingRight="15px";
  970. }
  971.  
  972. //Build Wikipedia Label
  973. let WP_image_link = document.createElement("a");
  974. let WP_image = document.createElement("img");
  975. let WP_image_div = document.createElement("div");
  976. let WP_link = document.createElement("a");
  977. let WP_link_div = document.createElement("div");
  978. let WP_div = document.createElement("div");
  979. if(TMDB_title!==0){
  980. WP_image.src="https://i.postimg.cc/C5nzTd6y/wiki.png"; WP_image.style.width="46px"; WP_image.style.paddingBottom="18px"; WP_image.style.borderRadius = '3px';
  981. WP_image_link.href="https://en.wikipedia.org/w/index.php?search="+TMDB_title;
  982. WP_image_link.append(WP_image);
  983. WP_image_div.append(WP_image_link);
  984.  
  985. //YT_link.innerText="Trailer"; YT_link.href=YT_image_link.href; YT_link.style.color="red"; YT_link.style.fontSize="80%"; YT_link.style.marginLeft="4px";
  986. //YT_link_div.append(YT_link);
  987.  
  988. WP_div.append(WP_image_div);
  989. }
  990.  
  991.  
  992. //Build Oscars Label
  993. let AWARDS_image = document.createElement("img");
  994. let AWARDS_link = document.createElement("a");
  995. let AWARDS_div = document.createElement("div");
  996. if(IMDB_awards!==0){
  997. AWARDS_image.src="https://i.postimg.cc/bvtXCJcS/5131089.png"; AWARDS_image.style.width="28px";AWARDS_image.style.display="inline";
  998. AWARDS_link.innerText=IMDB_awards; AWARDS_link.href="https://www.imdb.com/title/"+IMDB_id+"/awards/"; AWARDS_link.style.fontSize="90%"; AWARDS_link.style.paddingLeft="5px";
  999. AWARDS_div.append(AWARDS_image,AWARDS_link); AWARDS_div.style.paddingTop="25px";
  1000. }
  1001.  
  1002. //Build Original Title
  1003. let OT_header = document.createElement("h3");
  1004. if(TMDB_original_title!==0){
  1005. OT_header.innerText=TMDB_original_title;
  1006. let title_hook=document.getElementsByClassName("title ott_true")[0];
  1007. if(title_hook!==undefined) {
  1008. let h2_hook = title_hook.getElementsByTagName("h2")[0];
  1009. if(h2_hook!==undefined) h2_hook.after(OT_header);
  1010. }
  1011. }
  1012.  
  1013. //Remove Loading
  1014. page_score_icon[0].nextSibling.remove();
  1015.  
  1016. //Append SCORES
  1017. if(anime_flag!==0) page_score_icon[0].after(IMDB_div,LB_div,RT_div,MC_div,MAL_div,WP_div,YT_div); else page_score_icon[0].after(IMDB_div,LB_div,RT_div,MC_div,WP_div,YT_div);
  1018.  
  1019. //Append AWARDS
  1020. let top_bar = document.getElementsByClassName("auto actions");
  1021. if(IMDB_awards!==0) top_bar[0].after(AWARDS_div);
  1022.  
  1023. //set runtime color
  1024. let runtime_div= document.querySelectorAll(".facts")[0].querySelectorAll(".runtime")[0];
  1025. if(runtime_div!== undefined) runtime_div.style.color="orange";
  1026.  
  1027. }
  1028.  
  1029. main();