// ==UserScript== // @name trakt.tv grid++ IMDb, MetaCritic & RottenTomatoes movie ratings + links // @namespace https://greasyfork.org/en/users/167473-benedict-harris // @author jesuis-parapluie (plus modifications by Benedict) // @description Inserts movie ratings from IMDb, RottenTomatoes and Metacritic ratings in any grid view // // @include /^https?://(.+\.)?trakt\.tv/?.*$/ // @exclude /^https?://(.+\.)?trakt\.tv/(calendars)/?.*$/ // // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js // // @grant GM_xmlhttpRequest // // @version 2.2.3 // // @downloadURL https://update.greasyfork.icu/scripts/375966/trakttv%20grid%2B%2B%20IMDb%2C%20MetaCritic%20%20RottenTomatoes%20movie%20ratings%20%2B%20links.user.js // @updateURL https://update.greasyfork.icu/scripts/375966/trakttv%20grid%2B%2B%20IMDb%2C%20MetaCritic%20%20RottenTomatoes%20movie%20ratings%20%2B%20links.meta.js // ==/UserScript== /*==================NOTE - REPLACE the eight @ symbols on the line below (line 22) with your API from www.omdbapi.com (its free) ====================*/ var API = '@@@@@@@@'; (function ($) { 'use strict'; /*jslint browser: true, regexp: true, newcap: true*/ /*global jQuery, GM_xmlhttpRequest */ $.noConflict(); var loadRatingsForItem = function () { var imdb = $('', { 'class': 'ratings', 'html': '
 ' }), tomatoes = $('', { 'class': 'ratings', 'html': '
 ' }), dummy = $('', { 'class': 'ratings', 'style': 'opacity: 0.8; height: 18px;' }), url = $(this).attr('data-url'); if ($(this).attr('data-type') !== 'movie' && ($(this).attr('data-type') !== 'show')) { $(this).find('.quick-icons').after(dummy).after(dummy.clone()); } else { $(this).find('.quick-icons').after(tomatoes).after(imdb); if (url) { $(imdb).find('span.value').html('          loading'); $.get(url, function (data) { var imdb_id = $(data).find('.external a:contains("IMDB")').attr('href').split('/').pop(); GM_xmlhttpRequest({ method: "GET", url: "http://www.omdbapi.com/?plot=short&tomatoes=true&r=json&apikey=" + API + "&i=" + imdb_id, onload: function (json) { var rtcolour = '#FF5555'; var rtimglink = 'https://www.rottentomatoes.com/assets/pizza-pie/images/icons/tomatometer/tomatometer-fresh.149b5e8adc3.svg'; var imdbimglink = 'https://ia.media-imdb.com/images/M/MV5BMTk3ODA4Mjc0NF5BMl5BcG5nXkFtZTgwNDc1MzQ2OTE@._V1_.png'; var metacimglink = 'https://upload.wikimedia.org/wikipedia/commons/2/20/Metacritic.svg'; var rtimglong = 'rt'; var r, res = $.parseJSON(json.responseText); for (r in res.Ratings) { if (res.Ratings.hasOwnProperty(r) && res.Ratings[r].Source === "Rotten Tomatoes") { res.tomatoRating = res.Ratings[r].Value; } } var yearja = res.Year; if (res.Type == 'series'){ //yearja = res.Year.match(/^..../ig); console.log('oneyear ='+yearja); //res.tomatoRating = 'tv ➔'; //res.tomatoRating = '❯❯❯'; res.tomatoRating = 'TV'; rtimglong = ""; res.tomatoURL = "https://duckduckgo.com/?q=site%3Arottentomatoes.com+"+res.Title+"+"+res.Year+"+!&t=hg"; } var metalink = "https://duckduckgo.com/?q=site%3Ametacritic.com+"+res.Title+"+"+yearja+"+!&t=hg"; //var metalink = "https://duckduckgo.com/?q=site%3Ametacritic.com+"+res.Title+"+"+res.Year+"+!"; //console.log('METALINK'); //console.log(metalink); //console.log('++'); //console.log("console.log(res.tomatoURL)"); //console.log(res.tomatoURL); //console.log("console.dir(res);"); //console.dir(res); //console.log("console.log(json);"); //console.dir(json); //console.log("console.log(res.Response)"); //console.log(res.Response); if (res.tomatoRating === undefined || res.tomatoRating === "N/A") { res.tomatoRating = '-'; res.tomatoURL = "https://duckduckgo.com/?q=site%3Arottentomatoes.com+"+res.Title+"+"+res.Year+"+!&t=hg"; console.log('NULLLLLLLLLLLLLLLLLLLLLLLLLLLLLL'); rtimglink = ''; rtimglong = ''; } if (parseFloat(res.tomatoRating) < 60 ) { rtcolour = '#00CA5F'; rtimglink = 'https://www.rottentomatoes.com/assets/pizza-pie/images/icons/tomatometer/tomatometer-rotten.f1ef4f02ce3.svg'; rtimglong = 'rt'; } if (res.Metascore === undefined || res.Metascore === "N/A") { if (res.Type == 'series'){ //res.Metascore = 'tv ➔'; //res.Metascore = '❯❯❯'; res.Metascore = 'TV'; } else { res.Metascore = '-'; } } if (API == '@@@@@@@@'){ res.tomatoRating = 'you didnt read instructions.
put in your API in line 22.'; res.Metascore = ''; } if (res.imdbRating === undefined || res.imdbRating === "N/A") { $(imdb).find('span.value').html('     -'); } else { /*console.log('============================' + res.tomatoRating);*/ $(imdb).find('span.value').html('' + res.imdbRating + ''); } $(tomatoes).find('span.value').html(' ' + res.Metascore + '
' + res.Plot + '
' + rtimglong + '' + res.tomatoRating + '
'); }, onerror: function () { $(imdb).find('span.value').html('          failed'); } }); }).fail(function () { $(imdb).find('span.value').html('          failed'); }); } } }, parseRating = function (item, type) { var r; if (type === 'originalOrder') { return $(item).attr('startOrder'); } if (type === 'trakt') { r = $(item).find("div.percentage").text().slice(0, -1); if (r !== null && r >= 0 && r <= 100) { return r; } } if (type === 'imdb') { r = $(item).find("span.ratings").text().match(/IMDb\W+(\d(\.\d)?).*/i); } if (type === 'tomatometer') { r = $(item).find("span.ratings").text().match(/R\.T\.[^\d]+(\d*)%?.*/i); } if (type === 'metascore') { r = $(item).find("span.ratings").text().match(/R\.T\. \/[^\/]+\/\W*(\d+).*/i); } if (r !== null && r.length > 1 && r[1] !== '-') { return r[1]; } return -1; }, sortByRating = function (e) { var items, order, dict = {}, parent = $("div.grid-item").parent(), how = function (a, b) { return a - b; }; $(".no-top").hide(); if ($('#sortable-name').size() > 0) { $('#sortable-name').text($(e.target).text()).attr('data-sort-by', $(e.target).attr('data-sort-by')); } else { $('.trakt-icon-swap-vertical').next().find('.btn-default').html($(e.target).text() + ' '); } $("div.grid-item").each(function () { var rating = parseRating(this, $(e.target).attr('data-sort-by')); if (dict[rating] === undefined) { dict[rating] = [$(this)]; } else { dict[rating].push($(this)); } }); if ($('#sort-direction').hasClass('desc')) { how = function (b, a) { return a - b; }; } order = Object.keys(dict).sort(how); while (order.length > 0) { items = dict[order.pop()]; while (items.length > 0) { parent.append(items.shift()); } } }, setPositioning = function () { setTimeout(function () { if ($('.trakt-icon-swap-vertical').next().find('a.rating:contains("' + $('.trakt-icon-swap-vertical').next().find('.btn-default').text().trim() + '")').size() > 0) { $("div.grid-item").each(function () { $(this).attr('style', '{position:relative;top:0px;left:0px;}'); }); } else if ($('.grid-item').first().attr('style') !== undefined) { $("div.grid-item").each(function () { $(this).css('position', 'absolute'); }); } }, 500); }, init = function () { $("div[id*=\"huckster-desktop\"]").html(""); if (/^\/users\/.+\/(collection|ratings|lists\/|watchlist)/.test(window.location.pathname) && $('.trakt-icon-swap-vertical').next().find('ul a.rating').size() === 0) { var sortMenu = $('.trakt-icon-swap-vertical').next().find('ul'); sortMenu.append($('
  • ', { html: "IMDb rating" })); sortMenu.append($('
  • ', { html: "TomatoMeter" })); sortMenu.append($('
  • ', { html: "Metascore" })); sortMenu.find('a.rating').click(sortByRating); sortMenu.find('a').click(setPositioning); $(window).on('resize', setPositioning); $('#sort-direction').click(function () { $('.trakt-icon-swap-vertical').next().find('a.rating:contains("' + $('.trakt-icon-swap-vertical').next().find('.btn-default').text().trim() + '")').click(); }); } else { $(window).off('resize', setPositioning); } if (($("div.grid-item[data-type='movie']").size() > 0||$("div.grid-item[data-type='show']").size() > 0)) { $("div.grid-item").not('.ratingsloaded').each(loadRatingsForItem); } }; $(window).ready(function () { $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); // one below kills ads $('head').append(''); $('head').append(''); //$('head').append(''); $('head').append(''); $('head').append(''); $('head').append(''); init(); $(window).on('DOMNodeInserted', function (e) { if (e.target.tagName === 'BODY') { $(e.target).ready(init); } }); }); }(jQuery));