Show Metacritic.com ratings (Safari)

Show metacritic metascore and user ratings on: Bandcamp, Apple Itunes (Music), Amazon (Music,Movies,TV Shows), IMDb (Movies), Google Play (Music, Movies), TV.com, Steam, Gamespot (PS4, XONE, PC), Rotten Tomatoes, Serienjunkies, BoxOfficeMojo, allmovie.com, movie.com, Wikipedia (en), themoviedb.org, letterboxd, TVmaze, TVGuide, followshows.com, TheTVDB.com, ConsequenceOfSound, Pitchfork, Last.fm, TVNfo, rateyourmusic.com

بۇ قوليازمىنى قاچىلاش؟
ئاپتورنىڭ تەۋسىيەلىگەن قوليازمىسى

سىز بەلكىم Show Rottentomatoes meter نى ياقتۇرۇشىڭىز مۇمكىن.

بۇ قوليازمىنى قاچىلاش
  1. // ==UserScript==
  2. // @name Show Metacritic.com ratings (Safari)
  3. // @description Show metacritic metascore and user ratings on: Bandcamp, Apple Itunes (Music), Amazon (Music,Movies,TV Shows), IMDb (Movies), Google Play (Music, Movies), TV.com, Steam, Gamespot (PS4, XONE, PC), Rotten Tomatoes, Serienjunkies, BoxOfficeMojo, allmovie.com, movie.com, Wikipedia (en), themoviedb.org, letterboxd, TVmaze, TVGuide, followshows.com, TheTVDB.com, ConsequenceOfSound, Pitchfork, Last.fm, TVNfo, rateyourmusic.com
  4. // @namespace cuzi
  5. // @grant GM_xmlhttpRequest
  6. // @grant GM_setValue
  7. // @grant GM_getValue
  8. // @grant unsafeWindow
  9. // @grant GM.xmlHttpRequest
  10. // @grant GM.setValue
  11. // @grant GM.getValue
  12. // @require http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
  13. // @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
  14. // @version 51
  15. // @connect metacritic.com
  16. // @connect php-cuzi.herokuapp.com
  17. // @include https://*.bandcamp.com/*
  18. // @include https://play.google.com/store/music/album/*
  19. // @include https://play.google.com/store/movies/details/*
  20. // @include https://music.amazon.com/*
  21. // @include http://www.amazon.com/*
  22. // @include https://www.amazon.com/*
  23. // @include http://www.amazon.co.uk/*
  24. // @include https://www.amazon.co.uk/*
  25. // @include http://www.amazon.fr/*
  26. // @include https://www.amazon.fr/*
  27. // @include http://www.amazon.de/*
  28. // @include https://www.amazon.de/*
  29. // @include http://www.amazon.es/*
  30. // @include https://www.amazon.es/*
  31. // @include http://www.amazon.ca/*
  32. // @include https://www.amazon.ca/*
  33. // @include http://www.amazon.in/*
  34. // @include https://www.amazon.in/*
  35. // @include http://www.amazon.it/*
  36. // @include https://www.amazon.it/*
  37. // @include http://www.amazon.co.jp/*
  38. // @include https://www.amazon.co.jp/*
  39. // @include http://www.amazon.com.mx/*
  40. // @include https://www.amazon.com.mx/*
  41. // @include http://www.amazon.com.au/*
  42. // @include https://www.amazon.com.au/*
  43. // @include http://www.imdb.com/title/*
  44. // @include https://www.imdb.com/title/*
  45. // @include http://store.steampowered.com/app/*
  46. // @include https://store.steampowered.com/app/*
  47. // @include http://www.gamespot.com/*
  48. // @include https://www.gamespot.com/*
  49. // @include http://www.serienjunkies.de/*
  50. // @include https://www.serienjunkies.de/*
  51. // @include http://www.tv.com/shows/*
  52. // @include http://www.rottentomatoes.com/m/*
  53. // @include https://www.rottentomatoes.com/m/*
  54. // @include http://www.rottentomatoes.com/tv/*
  55. // @include https://www.rottentomatoes.com/tv/*
  56. // @include http://www.rottentomatoes.com/tv/*/s*/
  57. // @include https://www.rottentomatoes.com/tv/*/s*/
  58. // @include http://www.boxofficemojo.com/movies/*
  59. // @include https://www.boxofficemojo.com/movies/*
  60. // @include http://www.allmovie.com/movie/*
  61. // @include https://www.allmovie.com/movie/*
  62. // @include https://en.wikipedia.org/*
  63. // @include http://www.movies.com/*/m*
  64. // @include https://www.themoviedb.org/movie/*
  65. // @include https://www.themoviedb.org/tv/*
  66. // @include http://letterboxd.com/film/*
  67. // @include https://letterboxd.com/film/*
  68. // @exclude https://letterboxd.com/film/*/image*
  69. // @include http://www.tvmaze.com/shows/*
  70. // @include https://www.tvmaze.com/shows/*
  71. // @include http://www.tvguide.com/tvshows/*
  72. // @include https://www.tvguide.com/tvshows/*
  73. // @include http://followshows.com/show/*
  74. // @include https://followshows.com/show/*
  75. // @include http://thetvdb.com/*tab=series*
  76. // @include https://thetvdb.com/*tab=series*
  77. // @include http://www.thetvdb.com/*tab=series*
  78. // @include https://www.thetvdb.com/*tab=series*
  79. // @include https://www.thetvdb.com/series/*
  80. // @include http://consequenceofsound.net/*
  81. // @include https://consequenceofsound.net/*
  82. // @include http://pitchfork.com/*
  83. // @include https://pitchfork.com/*
  84. // @include http://www.last.fm/*
  85. // @include https://www.last.fm/*
  86. // @include http://tvnfo.com/s/*
  87. // @include https://tvnfo.com/s/*
  88. // @include http://rateyourmusic.com/release/album/*
  89. // @include https://rateyourmusic.com/release/album/*
  90. // @include https://open.spotify.com/*
  91. // @include https://play.spotify.com/album/*
  92. // @include https://www.nme.com/reviews/*
  93. // @include https://www.albumoftheyear.org/album/*
  94. // @include https://itunes.apple.com/*/movie/*
  95. // @include https://itunes.apple.com/*/album/*
  96. // @include https://itunes.apple.com/*/tv-season/*
  97. // @include http://epguides.com/*
  98. // @include http://www.epguides.com/*
  99. // @include https://sharetv.com/shows/*
  100. // ==/UserScript==
  101.  
  102.  
  103.  
  104. // ###### For Safari
  105. if (!String.prototype.startsWith) {
  106. String.prototype.startsWith = function(searchString, position) {
  107. position = position || 0;
  108. return this.indexOf(searchString, position) === position;
  109. };
  110. }
  111. // ###### For Safari
  112. if (!String.prototype.normalize) {
  113. String.prototype.normalize = function(s) {
  114. return ""+this;
  115. };
  116. }
  117.  
  118.  
  119. var baseURL = "https://www.metacritic.com/";
  120.  
  121. var baseURL_music = "https://www.metacritic.com/music/";
  122. var baseURL_movie = "https://www.metacritic.com/movie/";
  123. var baseURL_pcgame = "https://www.metacritic.com/game/pc/";
  124. var baseURL_ps4 = "https://www.metacritic.com/game/playstation-4/";
  125. var baseURL_xone = "https://www.metacritic.com/game/xbox-one/";
  126. var baseURL_tv = "https://www.metacritic.com/tv/";
  127.  
  128. var baseURL_search = "https://www.metacritic.com/search/{type}/{query}/results";
  129. var baseURL_autosearch = "https://www.metacritic.com/autosearch";
  130.  
  131. var baseURL_database = "https://php-cuzi.herokuapp.com/r.php";
  132. var baseURL_whitelist = "https://php-cuzi.herokuapp.com/whitelist.php";
  133. var baseURL_blacklist = "https://php-cuzi.herokuapp.com/blacklist.php";
  134.  
  135. // http://www.designcouch.com/home/why/2013/05/23/dead-simple-pure-css-loading-spinner/
  136. var CSS = "#mcdiv123 .grespinner{height:16px;width:16px;margin:0 auto;position:relative;-webkit-animation:rotation .6s infinite linear;-moz-animation:rotation .6s infinite linear;-o-animation:rotation .6s infinite linear;animation:rotation .6s infinite linear;border-left:6px solid rgba(0,174,239,.15);border-right:6px solid rgba(0,174,239,.15);border-bottom:6px solid rgba(0,174,239,.15);border-top:6px solid rgba(0,174,239,.8);border-radius:100%}@-webkit-keyframes rotation{from{-webkit-transform:rotate(0)}to{-webkit-transform:rotate(359deg)}}@-moz-keyframes rotation{from{-moz-transform:rotate(0)}to{-moz-transform:rotate(359deg)}}@-o-keyframes rotation{from{-o-transform:rotate(0)}to{-o-transform:rotate(359deg)}}@keyframes rotation{from{transform:rotate(0)}to{transform:rotate(359deg)}}#mcdiv123searchresults .result{font:12px arial,helvetica,serif;border-top-width:1px;border-top-color:#ccc;border-top-style:solid;padding:5px}#mcdiv123searchresults .result .result_type{display:inline}#mcdiv123searchresults .result .result_wrap{float:left;width:100%}#mcdiv123searchresults .result .has_score{padding-left:42px}#mcdiv123searchresults .result .basic_stats{height:1%;overflow:hidden}#mcdiv123searchresults .result h3{font-size:14px;font-weight:700}#mcdiv123searchresults .result a{color:#09f;font-weight:700;text-decoration:none}#mcdiv123searchresults .metascore_w.game.seventyfive,#mcdiv123searchresults .metascore_w.positive,#mcdiv123searchresults .metascore_w.score_favorable,#mcdiv123searchresults .metascore_w.score_outstanding,#mcdiv123searchresults .metascore_w.sixtyone{background-color:#6c3}#mcdiv123searchresults .metascore_w.forty,#mcdiv123searchresults .metascore_w.game.fifty,#mcdiv123searchresults .metascore_w.mixed,#mcdiv123searchresults .metascore_w.score_mixed{background-color:#fc3}#mcdiv123searchresults .metascore_w.negative,#mcdiv123searchresults .metascore_w.score_terrible,#mcdiv123searchresults .metascore_w.score_unfavorable{background-color:red}#mcdiv123searchresults a.metascore_w,#mcdiv123searchresults span.metascore_w{display:inline-block}#mcdiv123searchresults .result .metascore_w{color:#fff!important;font-family:Arial,Helvetica,sans-serif;font-size:17px;font-style:normal!important;font-weight:700!important;height:2em;line-height:2em;text-align:center;vertical-align:middle;width:2em;float:left;margin:0 0 0 -42px}#mcdiv123searchresults .result .more_stats{font-size:10px;color:#444}#mcdiv123searchresults .result .release_date .data{font-weight:700;color:#000}#mcdiv123searchresults ol,#mcdiv123searchresults ul{list-style:none}#mcdiv123searchresults .result li.stat{background:0 0;display:inline;float:left;margin:0;padding:0 6px 0 0;white-space:nowrap}#mcdiv123searchresults .result .deck{margin:3px 0 0}#mcdiv123searchresults .result .basic_stat{display:inline;float:right;overflow:hidden;width:100%}";
  137.  
  138. var myDOMParser = null;
  139. function domParser() {
  140. if(myDOMParser===null) {
  141. myDOMParser = new DOMParser()
  142. }
  143. return myDOMParser;
  144. }
  145.  
  146. function versionUpdate() {
  147. let version = parseInt(GM_getValue("version", 0));
  148. if(version <= 46) {
  149. // Reset database
  150. GM_setValue("map", "{}");
  151. GM_setValue("black", "{}");
  152. GM_setValue("hovercache", "{}");
  153. GM_setValue("searchcache", "{}");
  154. GM_setValue("autosearchcache", "{}");
  155. }
  156. if(version < 48) {
  157. GM_setValue("version", 48);
  158. }
  159. }
  160.  
  161. function getHostname(url) {
  162. with(document.createElement("a")) {
  163. href = url;
  164. return hostname;
  165. }
  166. }
  167. function absoluteMetaURL(url) {
  168. if(url.startsWith("https://")) {
  169. return url;
  170. }
  171. if(url.startsWith("http://")) {
  172. return "https" + url.substr(4);
  173. }
  174. if(url.startsWith("//")) {
  175. return baseURL + url.substr(2);
  176. }
  177. if(url.startsWith("/")) {
  178. return baseURL + url.substr(1);
  179. }
  180. return baseURL + url;
  181. }
  182.  
  183. var parseLDJSON_cache = {}
  184. function parseLDJSON(keys, condition) {
  185. if(document.querySelector('script[type="application/ld+json"]')) {
  186. var data = [];
  187. var scripts = document.querySelectorAll('script[type="application/ld+json"]');
  188. for(let i = 0; i < scripts.length; i++) {
  189. var jsonld;
  190. if (scripts[i].innerText in parseLDJSON_cache) {
  191. jsonld = parseLDJSON_cache[scripts[i].innerText]
  192. } else {
  193. try {
  194. jsonld = JSON.parse(scripts[i].innerText);
  195. parseLDJSON_cache[scripts[i].innerText] = jsonld
  196. } catch(e) {
  197. parseLDJSON_cache[scripts[i].innerText] = null
  198. continue;
  199. }
  200. }
  201. if(jsonld) {
  202. if(Array.isArray(jsonld)) {
  203. data.push(...jsonld)
  204. } else {
  205. data.push(jsonld);
  206. }
  207. }
  208. }
  209. for(let i = 0; i < data.length; i++) {
  210. try {
  211. if(data[i] && data[i] && (typeof condition != 'function' || condition(data[i]))) {
  212. if(Array.isArray(keys)) {
  213. let r = [];
  214. for(let j = 0; j < keys.length; j++) {
  215. r.push(data[i][keys[j]]);
  216. }
  217. return r;
  218. } else if(keys) {
  219. return data[i][keys];
  220. } else if(typeof condition === 'function') {
  221. return data[i]; // Return whole object
  222. }
  223. }
  224. } catch(e) {
  225. continue;
  226. }
  227. }
  228. return data;
  229. }
  230. return null;
  231. }
  232.  
  233. function name2metacritic(s) {
  234. return s.normalize('NFKD').replace(/\//g,"").replace(/[\u0300-\u036F]/g, '').replace(/&/g,"and").replace(/\W+/g, " ").toLowerCase().trim().replace(/\W+/g,"-");
  235. }
  236. function minutesSince(time) {
  237. var seconds = ((new Date()).getTime() - time.getTime()) / 1000;
  238. return seconds>60?parseInt(seconds/60)+" min ago":"now";
  239. }
  240. function randomStringId() {
  241. var id10 = function() { return Math.floor((1 + Math.random()) * 0x10000000000).toString(16).substring(1); };
  242. return id10()+id10()+id10()+id10()+id10()+id10();
  243. }
  244. function fixMetacriticURLs(html) {
  245. return html.replace(/<a /g,'<a target="_blank" ').replace(/href="\//g,'href="'+baseURL).replace(/src="\//g,'src="'+baseURL);
  246. }
  247. function searchType2metacritic(type) {
  248. return ({
  249. 'movie' : 'movie',
  250. 'pcgame' : 'game',
  251. 'xonegame' : 'game',
  252. 'ps4game' : 'game',
  253. 'music' : 'album',
  254. 'tv' : 'tv'
  255. })[type];
  256. }
  257. function metacritic2searchType(type) {
  258. return ({
  259. "Album" : "music",
  260. "TV" : "tv",
  261. "Movie" : "movie",
  262. "PC Game" : "pcgame",
  263. "PS4 Game" : "ps4game",
  264. "XONE Game" : "onegame",
  265. "WIIU Game" : "xxxxx",
  266. "3DS Game" : "xxxx"
  267. })[type];
  268. }
  269.  
  270.  
  271. function metaScore(score, word) {
  272. var fg,bg,t;
  273. if(score == null) {
  274. fg = "black";
  275. bg = "#ccc";
  276. t = "tbd";
  277. } else if(score >= 75) {
  278. fg = "white";
  279. bg = "#6c3";
  280. t = parseInt(score);
  281. } else if(score < 40) {
  282. fg = "white";
  283. bg = "#f00";
  284. t = parseInt(score);
  285. } else {
  286. fg = "white";
  287. bg = "#fc3";
  288. t = parseInt(score);
  289. }
  290.  
  291. return '<span title="'+(word?word:'')+'" style="display: inline-block; color: '+fg+';background:'+bg+';font-family: Arial,Helvetica,sans-serif;font-size: 17px;font-style: normal;font-weight: bold;height: 2em;width: 2em;line-height: 2em;text-align: center;vertical-align: middle;">'+t+'</span>';
  292. }
  293.  
  294. function balloonAlert(message, timeout, title, css, click) {
  295. var header;
  296. if(title) {
  297. header = '<div style="background:rgb(220,230,150); padding: 2px 12px;">' + title +"</div>";
  298. } else if(title === false) {
  299. header = '';
  300. } else {
  301. header = '<div style="background:rgb(220,230,150); padding: 2px 12px;">Userscript alert</div>';
  302. }
  303. var div = $("<div>" + header + '<div style="padding:5px">' + message.split("\n").join("<br>") + "</div></div>");
  304. div.css({
  305. position : "fixed",
  306. top : 10,
  307. left : 10,
  308. maxWidth: 200,
  309. zIndex : "5010002",
  310. background : "rgb(240,240,240)",
  311. border : "2px solid yellow",
  312. borderRadius :"6px",
  313. boxShadow: "0 0 3px 3px rgba(100, 100, 100, 0.2)",
  314. fontFamily: "sans-serif",
  315. color: "black"
  316. });
  317. if(css) {
  318. div.css(css);
  319. }
  320. div.appendTo(document.body);
  321.  
  322. if(click) {
  323. div.click(function(ev) {
  324. $(this).hide(500);
  325. click.call(this,ev);
  326. });
  327. }
  328.  
  329. if(!click) {
  330. var close = $('<div title="Close" style="cursor:pointer; position:absolute; top:0px; right:3px;">&#10062;</div>').appendTo(div);
  331. close.click(function(){
  332. $(this.parentNode).hide(1000);
  333. });
  334. }
  335.  
  336. if(timeout && timeout > 0) {
  337. window.setTimeout(function() {
  338. div.hide(3000);
  339. }, timeout);
  340. }
  341. return div;
  342. }
  343.  
  344. function filterUniversalUrl(url) {
  345. try {
  346. url = url.match(/http?.+/)[0];
  347. } catch(e) { }
  348.  
  349. try {
  350. url = url.replace(/https?:\/\/(www.)?/,"");
  351. } catch(e) { }
  352.  
  353. if(url.startsWith("imdb.com/") && url.match(/(imdb\.com\/\w+\/\w+\/)/)) {
  354. // Remove movie subpage from imdb url
  355. return url.match(/(imdb\.com\/\w+\/\w+\/)/)[1];
  356. } else if(url.startsWith("thetvdb.com/")) {
  357. // Do nothing with thetvdb.com urls
  358. return url;
  359. } else if(url.startsWith("boxofficemojo.com/")) {
  360. // Keep the important id= on
  361. try {
  362. var parts = url.split("?");
  363. var page = url[0] + "?";
  364. var idparam = url[1].match(/(id=.+?)(\.|&)/)[1];
  365. return page+idparam;
  366. } catch(e) {
  367. return url;
  368. }
  369. } else {
  370. // Default: Remove parameters
  371. return url.split("?")[0].split("&")[0];
  372. }
  373. }
  374.  
  375. function addToMap(url, metaurl) {
  376. var data = JSON.parse(GM_getValue("map","{}"));
  377.  
  378. var url = filterUniversalUrl(url);
  379. var metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//,"");
  380.  
  381. data[url] = metaurl;
  382.  
  383. GM_setValue("map", JSON.stringify(data));
  384.  
  385. (new Image()).src = baseURL_whitelist + "?docurl="+encodeURIComponent(url)+"&metaurl="+encodeURIComponent(metaurl)+"&ref="+encodeURIComponent(randomStringId());
  386. return [url, metaurl];
  387. }
  388.  
  389. function addToBlacklist(url, metaurl) {
  390. var data = JSON.parse(GM_getValue("black","[]"));
  391.  
  392. var url = filterUniversalUrl(url);
  393. var metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//,"");
  394.  
  395. data.push([url,metaurl]);
  396.  
  397. GM_setValue("black", JSON.stringify(data));
  398.  
  399. (new Image()).src = baseURL_blacklist + "?docurl="+encodeURIComponent(url)+"&metaurl="+encodeURIComponent(metaurl)+"&ref="+encodeURIComponent(randomStringId());
  400. return [url, metaurl];
  401. }
  402.  
  403. function isBlacklistedUrl(docurl, metaurl) {
  404. docurl = filterUniversalUrl(docurl);
  405. docurl = docurl.replace(/https?:\/\/(www.)?/,"");
  406.  
  407. metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//,"");
  408. metaurl = metaurl.replace(/\/\//g,"/").replace(/\/\//g,"/");; // remove double slash
  409. metaurl = metaurl.replace(/^\/+/,""); // remove starting slash
  410.  
  411. var data = JSON.parse(GM_getValue("black","[]")); // [ [docurl0, metaurl0] , [docurl1, metaurl1] , ... ]
  412. for(var i = 0; i < data.length; i++) {
  413. if(data[i][0] == docurl && data[i][1] == metaurl) {
  414. return true;
  415. }
  416. }
  417. return false;
  418. }
  419.  
  420. function isBlacklisted(metaurl) {
  421. return isBlacklistedUrl("" + document.location.host.replace(/^www\./,"") + document.location.pathname + document.location.search, metaurl);
  422. }
  423.  
  424.  
  425.  
  426. function listenForHotkeys(code, cb) {
  427. // Call cb() as soon as the code sequence was typed
  428. var i = 0;
  429. $(document).bind("keydown.listenForHotkeys",function(ev) {
  430. if(document.activeElement == document.body) {
  431. if(ev.key != code[i]) {
  432. i = 0;
  433. } else {
  434. i++;
  435. if(i == code.length) {
  436. ev.preventDefault();
  437. $(document).unbind("keydown.listenForHotkeys");
  438. cb();
  439. }
  440. }
  441. }
  442. });
  443. }
  444.  
  445.  
  446. function metacritic_hoverInfo(url, docurl, cb, errorcb, nocache) {
  447. // Get the metacritic hover info. Requests are cached.
  448. var handleresponse = function(response, cached) {
  449.  
  450. if(response.status == 200 && response.responseText && cb) {
  451. if(~response.responseText.indexOf('"jsonRedirect"')) { // {"viewer":{},"mixpanelToken":"6e219fd....","mixpanelDistinctId":"255.255.255.255","omnitureDebug":0,"jsonRedirect":"\/movie\/national-lampoons-vacation"}
  452. var blacklistedredirect = false;
  453. var j = JSON.parse(response.responseText);
  454. current.url = absoluteMetaURL(j["jsonRedirect"]);
  455. delete cache[url]; // Delete original url from cache. The redirect URL will then be saved in metacritic_hoverInfo(...)
  456.  
  457. // Blacklist items from database received?
  458. if("blacklist" in j && j.blacklist && j.blacklist.length) {
  459. // Save new blacklist items
  460. var data = JSON.parse(GM_getValue("black","[]"));
  461. for(var i = 0; i < j.blacklist.length; i++) {
  462. var save_docurl = j.blacklist[i].docurl;
  463. var save_metaurl = j.blacklist[i].metaurl;
  464.  
  465. data.push([save_docurl,save_metaurl]);
  466. if(j["jsonRedirect"] == "/"+save_metaurl) {
  467. // Redirect is blacklisted!
  468. blacklistedredirect = true;
  469. }
  470. }
  471. GM_setValue("black", JSON.stringify(data));
  472. }
  473. if(blacklistedredirect && errorcb) {
  474. // Redirect was blacklisted, show nothing
  475. errorcb(response.responseText, new Date(response.time));
  476. } else {
  477. // Load redirect
  478. metacritic_hoverInfo(absoluteMetaURL(j["jsonRedirect"]), false, cb, errorcb, true);
  479. }
  480. } else {
  481. cb(response.responseText, new Date(response.time));
  482. }
  483. } else if(response.status != 200 && errorcb) {
  484. errorcb(response.responseText, new Date(response.time));
  485. if(!cached)
  486. console.log("Show metacritic ratings: Error 01:"+response.status+"\n"+url);
  487. } else if(!response.responseText) {
  488. errorcb("", new Date(response.time));
  489. if(!cached)
  490. console.log("Show metacritic ratings: Error 02: response empty. Status:"+response.status+"\n"+url);
  491. }
  492. };
  493.  
  494. var cache = JSON.parse(GM_getValue("hovercache","{}"));
  495. for(var prop in cache) {
  496. // Delete cached values, that are older than 2 hours
  497. if((new Date()).getTime() - (new Date(cache[prop].time)).getTime() > 2*60*60*1000) {
  498. delete cache[prop];
  499. }
  500. }
  501.  
  502. if(!nocache && url in cache) {
  503. handleresponse(cache[url], true);
  504. } else {
  505. var requestURL = url;
  506. var requestParams = "hoverinfo=1";
  507.  
  508. if(docurl && docurl.indexOf("metacritic.com") == -1 && docurl.indexOf(baseURL_database) == -1) {
  509. // Ask database for correct metacritic entry:
  510. requestURL = baseURL_database;
  511. requestParams = "m=" + encodeURIComponent(docurl) + "&a=" + encodeURIComponent(url);
  512. }
  513.  
  514. GM_xmlhttpRequest({
  515. method: "POST",
  516. url: requestURL,
  517. data: requestParams,
  518. headers: {
  519. "Referer" : url,
  520. "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8",
  521. "Host" : getHostname(requestURL), // This is important, otherwise Metacritic refuses to answer!
  522. "User-Agent" : navigator.userAgent,
  523. "X-Requested-With" : "XMLHttpRequest"
  524. },
  525. onload: function(response) {
  526. response.time = (new Date()).toJSON();
  527. cache[url] = response;
  528.  
  529. if(!response.responseText) {
  530. // Temporary fix:
  531. // Hover info seems to be available only for movies.
  532. requestURL = url;
  533. if(requestURL.indexOf('/critic-reviews') !== -1) {
  534. requestURL = url.split('/critic-reviews')[0]
  535. }
  536. GM_xmlhttpRequest({
  537. method: "GET",
  538. url: requestURL,
  539. headers: {
  540. "Referer" : url,
  541. "Host" : getHostname(requestURL), // This is important, otherwise Metacritic refuses to answer!
  542. //"User-Agent" : "MetacriticUserscript "+navigator.userAgent,
  543. "User-Agent" : navigator.userAgent
  544. },
  545. onload: function(response) {
  546. response.time = (new Date()).toJSON();
  547.  
  548. let html;
  549. try {
  550. // Try parsing HTML
  551.  
  552. let doc = domParser().parseFromString(response.responseText, 'text/html');
  553. doc.querySelector(".product_page_title h1")
  554. doc.querySelector(".summary_img")
  555. doc.querySelectorAll(".details_section")
  556. doc.querySelectorAll("#nav_to_metascore .distribution")
  557.  
  558.  
  559.  
  560. let page_url = img_src = img_alt = title = publisher = release_date = starring = critics_score = critics_class = critics_number = critics_charts = user_score = user_class = user_number = user_charts = ''
  561.  
  562. page_url = requestURL + (requestURL.endsWith("/") ? "" : "/")
  563. img_src = doc.querySelector(".summary_img").src
  564. img_alt = doc.querySelector(".summary_img").alt
  565. title = doc.querySelector(".product_page_title h1").textContent
  566. if(doc.querySelector(".details_section .distributor a"))
  567. publisher = doc.querySelector(".details_section .distributor a").textContent
  568.  
  569. if(doc.querySelector(".details_section .release_date span:nth-child(2)")) {
  570. let date = doc.querySelector(".details_section .release_date span:nth-child(2)").textContent
  571. release_date = `
  572. <div class="summary_detail release_data">
  573. <span class="label">Release Date:</span>
  574. <span class="data">${date}</span>
  575. </div>`
  576. }
  577.  
  578. if(doc.querySelector(".details_section.summary_cast span:nth-child(2)")) {
  579.  
  580. let stars = doc.querySelector(".details_section.summary_cast span:nth-child(2)").innerHTML
  581. starring = `
  582. <div>
  583. <div class="summary_detail product_credits">
  584. <span class="label">Starring:</span>
  585. <span class="data">
  586. ${stars}
  587. </span>
  588. </div>
  589. </div>`
  590. }
  591.  
  592. critics_class = "metascore_w medium tbd"
  593. critics_score = "tbd"
  594. user_class = "metascore_w medium user tbd"
  595. user_score = "tbd"
  596.  
  597. if(doc.querySelector(".score_details .based_on")) {
  598. critics_number = doc.querySelector(".score_details .based_on").textContent.match(/\d+/)
  599. } else {
  600. critics_number = "By"
  601. }
  602. if(doc.querySelector(".user_score_summary .based_on")) {
  603. user_number = doc.querySelector(".user_score_summary .based_on").textContent.match(/\d+/)
  604. } else {
  605. user_number = "User"
  606. }
  607.  
  608. // Remove text from distribution charts:
  609. let label = doc.querySelector("#nav_to_metascore .charts .label.fl")
  610. while(label) {
  611. label.parentNode.title = label.textContent.trim() + " " + label.parentNode.querySelector(".count").textContent.trim()
  612. label.remove()
  613. label = doc.querySelector("#nav_to_metascore .charts .label.fl")
  614. }
  615. let scores = doc.querySelectorAll("#nav_to_metascore .distribution .metascore_w")
  616. if(scores.length == 2) {
  617. critics_score = scores[0].innerText
  618. critics_class = scores[0].className.replace("larger", "medium")
  619. scores[0].parentNode.parentNode.querySelector(".charts").style.width = '40px'
  620. critics_charts = '<td class="meta">' + scores[0].parentNode.parentNode.querySelector(".charts").outerHTML + "</td>"
  621. user_score = scores[1].innerText
  622. user_class = scores[1].className.replace("larger", "medium")
  623. scores[1].parentNode.parentNode.querySelector(".charts").style.width = '40px'
  624. user_charts = '<td class="usr">' + scores[1].parentNode.parentNode.querySelector(".charts").outerHTML + "</td>"
  625. } else if(scores.length == 1) {
  626. if(scores[0].className.indexOf("user") === -1) {
  627. critics_score = scores[0].innerText
  628. critics_class = scores[0].className.replace("larger", "medium")
  629. scores[0].parentNode.parentNode.querySelector(".charts").style.width = '40px'
  630. critics_charts = '<td class="meta">' + scores[0].parentNode.parentNode.querySelector(".charts").outerHTML + "</td>"
  631. } else {
  632. user_score = scores[0].innerText
  633. user_class = scores[0].className.replace("larger", "medium")
  634. scores[0].parentNode.parentNode.querySelector(".charts").style.width = '40px'
  635. user_charts = '<td class="usr">' + scores[0].parentNode.parentNode.querySelector(".charts").outerHTML + "</td>"
  636. }
  637. }
  638.  
  639. html = `
  640. <div class="hoverinfo">
  641. <div class="hover_left">
  642. <div class="product_image_wrapper">
  643. <a target="_blank" href="${page_url}">
  644. <img class="product_image large_image" src="${img_src}" alt="${img_alt}" />
  645. </a>
  646. </div>
  647. </div>
  648. <div class="hover_right">
  649. <h2 class="product_title">
  650. <a target="_blank" href="${page_url}">${title}</a>
  651. </h2>
  652. <div>
  653. <div class="summary_detail publisher">
  654. <span class="data">${publisher}</span>
  655. <span>&nbsp;|&nbsp;&nbsp;</span>
  656. </div>
  657. ${release_date}
  658. <div class="clr"></div>
  659. </div>
  660. ${starring}
  661. <div class="hr">
  662. &nbsp;
  663. </div>
  664.  
  665. <table class="hover_scores ">
  666. <tr>
  667. <td class="meta num">
  668. <a target="_blank" class="metascore_anchor" href="${page_url}#nav_to_metascore">
  669. <span class="${critics_class}">${critics_score}</span>
  670. </a>
  671. </td>
  672. <td class="meta txt">
  673. <div class="metascore_label">Metascore</div>
  674. <div class="metascore_review_count">
  675. <a target="_blank" href="${page_url}#nav_to_metascore">
  676. <span>${critics_number}</span> critics
  677. </a>
  678. </div>
  679. </td>
  680. ${critics_charts}
  681. <td class="usr num">
  682.  
  683. <a target="_blank" class="metascore_anchor" href="${page_url}#nav_to_metascore">
  684. <span class="${user_class}">${user_score}</span>
  685. </a>
  686.  
  687. </td>
  688. <td class="usr txt">
  689. <div class="userscore_label">User Score</div>
  690. <div class="userscore_review_count">
  691. <a target="_blank" href="${page_url}#nav_to_metascore">
  692. <span>${user_number}</span> Ratings
  693. </a>
  694. </div>
  695. </td>
  696. ${user_charts}
  697. </tr>
  698. </table>
  699.  
  700. </div>
  701.  
  702. <div class="clr"></div>
  703. </div>
  704. `
  705. } catch(e) {
  706. console.log("Show metacritic ratings: Error parsing HTML: "+e);
  707. // fallback to cutting out the relevant parts
  708.  
  709. let parts = response.responseText.split('class="score_details')
  710. let text_part = '<div class="' + parts[1].split('</div>')[0] + '</div>'
  711.  
  712.  
  713. let title_text = '<div class="product_page_title' + response.responseText.split('class="product_page_title')[1].split('</div>')[0]
  714. title_text = title_text.split('<h1>').join('<h1 style="padding:0px; margin:2px">') + '</div>'
  715.  
  716. parts = response.responseText.split('id="nav_to_metascore"')
  717. let meta_score_part = '<div ' + parts[1].split('<div class="subsection_title"')[0] + '</div></div>'
  718.  
  719.  
  720. meta_score_part = meta_score_part.split('href="">').join('href="' + requestURL + '">')
  721. meta_score_part = meta_score_part.split('section_title bold">').join('section_title bold">' + title_text)
  722.  
  723. html = meta_score_part.split('<div class="distribution">').join(text_part + '<div class="distribution">')
  724.  
  725. if(html.indexOf('products_module') !== -1) {
  726. // Critic reviews are not available for this Series yet -> Cut the preview for other series
  727. html = html.split('products_module')[0] + '"></div>'
  728. }
  729.  
  730. if(html.length > 5000) {
  731. // Probably something went wrong, let's cut the response to prevent overly big content
  732. console.log("Show metacritic ratings: Cutting response to 5000 chars")
  733. html = html.substr(0, 5000)
  734. }
  735.  
  736. }
  737.  
  738. // Chrome fix: Otherwise JSON.stringify(cache) omits responseText
  739. var newobj = {};
  740. for(var key in response) {
  741. newobj[key] = response[key];
  742. }
  743. newobj.responseText = html;
  744.  
  745. //alert(requestURL+'\n'+requestParams+'\nResult:\n'+response.responseText)
  746.  
  747. cache[url] = newobj;
  748.  
  749. GM_setValue("hovercache",JSON.stringify(cache));
  750.  
  751. handleresponse(newobj, false);
  752. },
  753. onerror: function(response) {
  754. console.log("Show metacritic ratings: Hover info error 03: "+response.status+"\nURL: "+requestURL+"\nResponse:\n"+response.responseText);
  755. },
  756. });
  757.  
  758. } else {
  759.  
  760. // Chrome fix: Otherwise JSON.stringify(cache) omits responseText
  761. var newobj = {};
  762. for(var key in response) {
  763. newobj[key] = response[key];
  764. }
  765. newobj.responseText = response.responseText;
  766.  
  767.  
  768.  
  769. cache[url] = newobj;
  770.  
  771. GM_setValue("hovercache",JSON.stringify(cache));
  772.  
  773. handleresponse(response, false);
  774. }
  775. },
  776. onerror: function(response) {
  777. console.log("Show metacritic ratings: Hover info error 03: "+response.status+"\nURL: "+requestURL+"\nResponse:\n"+response.responseText);
  778. },
  779. });
  780. }
  781. }
  782. function metacritic_searchResults(url, cb, errorcb) {
  783. // Get metacritic search results. Requests are cached.
  784. var handleresponse = function(response, cached) {
  785. if(response.results.length && cb) {
  786. cb(response.results, new Date(response.time));
  787. } else if(response.results.length == 0 && errorcb) {
  788. errorcb(response.results, new Date(response.time));
  789. }
  790. };
  791.  
  792. var cache = JSON.parse(GM_getValue("searchcache","{}"));
  793. for(var prop in cache) {
  794. // Delete cached values, that are older than 2 hours
  795. if((new Date()).getTime() - (new Date(cache[prop].time)).getTime() > 2*60*60*1000) {
  796. delete cache[prop];
  797. }
  798. }
  799.  
  800. if(url in cache) {
  801. handleresponse(cache[url], true);
  802. } else {
  803. GM_xmlhttpRequest({
  804. method: "GET",
  805. url: url,
  806. headers: {
  807. "Referer" : url,
  808. "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8",
  809. "Host" : "www.metacritic.com",
  810. "User-Agent" : "MetacriticUserscript "+navigator.userAgent,
  811. },
  812. onload: function(response) {
  813.  
  814. var results = [];
  815. if(!~response.responseText.indexOf("No search results found.")) {
  816. var d = $('<html>').html(response.responseText);
  817. d.find("ul.search_results.module .result").each(function() {
  818. results.push(this.innerHTML);
  819. });
  820. }
  821.  
  822. response = {
  823. time : (new Date()).toJSON(),
  824. results : results,
  825. };
  826. cache[url] = response;
  827. GM_setValue("searchcache",JSON.stringify(cache));
  828. handleresponse(response, false);
  829. },
  830. onerror: function(response) {
  831. console.log("Show metacritic ratings: Search error 04: "+response.status+"\n"+url);
  832. handleresponse({
  833. time : (new Date()).toJSON(),
  834. results : [],
  835. }, false);
  836. }
  837. });
  838. }
  839. }
  840.  
  841. function metacritic_showHoverInfo(url, docurl) {
  842. if(!url) {
  843. return;
  844. }
  845. metacritic_hoverInfo(url, docurl?docurl:false,
  846. // On Success
  847. function(html, time) {
  848. $("#mcdiv123").remove();
  849. var div = $('<div id="mcdiv123"></div>').appendTo(document.body);
  850. div.css({
  851. position:"fixed",
  852. bottom :0,
  853. left: 0,
  854. minWidth: 300,
  855. backgroundColor: "#fff",
  856. border: "2px solid #bbb",
  857. borderRadius:" 6px",
  858. boxShadow: "0 0 3px 3px rgba(100, 100, 100, 0.2)",
  859. color: "#000",
  860. padding:" 3px",
  861. zIndex: "5010001",
  862. });
  863.  
  864. // Functions for communication between page and iframe
  865. // Mozilla can access parent.document
  866. // Chrome can use postMessage()
  867. var frame_status = false; // if this remains false, loading the frame content failed. A reason could be "Content Security Policy"
  868. function loadExternalImage(url, myframe) {
  869. // Load external image, bypass CSP
  870. GM_xmlhttpRequest({
  871. method: "GET",
  872. url: url,
  873. responseType : "arraybuffer",
  874. onload: function(response) {
  875. myframe.contentWindow.postMessage({
  876. "mcimessage_imgLoaded" : true,
  877. "mcimessage_imgData" : response.response,
  878. "mcimessage_imgOrgSrc" : url
  879. },'*');
  880. }
  881. });
  882. }
  883. var functions = {
  884. "parent" : function() {
  885. var f = parent.document.getElementById('mciframe123');
  886. var lastdiff = -200000;
  887. window.addEventListener("message", function(e){
  888. if(typeof e.data != "object") {
  889. return;
  890. } else if("mcimessage0" in e.data) {
  891. frame_status = true; // Frame content was loaded successfully
  892. } else if("mcimessage1" in e.data) {
  893. f.style.width = parseInt(f.style.width)+10+"px";
  894. if(e.data.heightdiff == lastdiff) {
  895. f.style.height = parseInt(f.style.height)+5+"px";
  896. }
  897. lastdiff = e.data.heightdiff;
  898.  
  899. } else if("mcimessage2" in e.data) {
  900. f.style.height = parseInt(f.style.height)+15+"px";
  901. f.style.width = "400px";
  902. } else if("mcimessage_loadImg" in e.data) {
  903. loadExternalImage(e.data.mcimessage_imgUrl, f);
  904. } else {
  905. return;
  906. }
  907. f.contentWindow.postMessage({
  908. "mcimessage3" : true,
  909. "mciframe123_clientHeight" : f.clientHeight,
  910. "mciframe123_clientWidth" : f.clientWidth,
  911. },'*');
  912. });
  913. },
  914. "frame" : function() {
  915. parent.postMessage({"mcimessage0":true},'*'); // Loading frame content was successfull
  916.  
  917. var i = 0;
  918. window.addEventListener("message", function(e){
  919. if(typeof e.data == "object" && "mcimessage_imgLoaded" in e.data) {
  920. // Load external image
  921. var arrayBufferView = new Uint8Array( e.data["mcimessage_imgData"] );
  922. var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
  923. var urlCreator = window.URL || window.webkitURL;
  924. var imageUrl = urlCreator.createObjectURL( blob );
  925. var img = failedImages[e.data["mcimessage_imgOrgSrc"]];
  926. img.src = imageUrl;
  927. }
  928.  
  929. if(!("mcimessage3" in e.data)) return;
  930.  
  931. if(e.data.mciframe123_clientHeight < document.body.scrollHeight && i < 100) {
  932. parent.postMessage({"mcimessage1":1, "heightdiff":document.body.scrollHeight - e.data.mciframe123_clientHeight},'*');
  933. i++;
  934. }
  935. if(i >= 100) {
  936. parent.postMessage({"mcimessage2":1},'*')
  937. i = 0;
  938. }
  939. });
  940. parent.postMessage({"mcimessage1":1,"heightdiff":-100000},'*');
  941. }
  942.  
  943. };
  944.  
  945.  
  946.  
  947. var css = "#hover_div .clr { clear: both} #hover_div .fl{float: left} #hover_div { background-color: #fff; color: #666; font-family:Arial,Helvetica,sans-serif; font-size:12px; font-weight:400; font-style:normal;} #hover_div .hoverinfo .hover_left { float: left} #hover_div .hoverinfo .product_image_wrapper { color: #999; font-size: 6px; font-weight: normal; min-height: 98px; min-width: 98px;} #hover_div .hoverinfo .product_image_wrapper a { color: #999; font-size: 6px; font-weight: normal;} #hover_div a * { cursor: pointer} #hover_div a { color: #09f; font-weight: bold;} #hover_div a:link, #hover_div a:visited { text-decoration: none;} #hover_div a:hover { text-decoration: underline;} #hover_div .hoverinfo .hover_right { float: left; margin-left: 15px; max-width: 395px;} #hover_div .hoverinfo .product_title { color: #333; font-family: georgia,serif; font-size: 24px; line-height: 26px; margin-bottom: 10px;} #hover_div .hoverinfo .product_title a { color:#333; font-family: georgia,serif; font-size: 24px;} #hover_div .hoverinfo .summary_detail.publisher, .hoverinfo .summary_detail.release_data { float: left} #hover_div .hoverinfo .summary_detail { font-size: 11px; margin-bottom: 10px;} #hover_div .hoverinfo .summary_detail.product_credits a { color: #999; font-weight: normal; } #hover_div .hoverinfo .hr { background-color: #ccc; height: 2px; margin: 15px 0 10px;} #hover_div .hoverinfo .hover_scores { width: 100%; border-collapse: collapse; border-spacing: 0;} #hover_div .hoverinfo .hover_scores td.num { width: 39px} #hover_div .hoverinfo .hover_scores td { vertical-align: middle} #hover_div caption, #hover_div th, #hover_div td { font-weight: normal; text-align: left;} #hover_div .metascore_anchor, #hover_div a.metascore_w { text-decoration: none !important} #hover_div span.metascore_w, #hover_div a.metascore_w { display: inline-block; padding:0px;}.metascore_w { background-color: transparent; color: #fff !important; font-family: Arial,Helvetica,sans-serif; font-size: 17px; font-style: normal !important; font-weight: bold !important; height: 2em; line-height: 2em; text-align: center; vertical-align: middle; width: 2em;} #hover_div .metascore, #hover_div .metascore a, #hover_div .avguserscore, #hover_div .avguserscore a { color: #fff} #hover_div .critscore, #hover_div .critscore a, #hover_div .userscore, #hover_div .userscore a { color: #333}.score_tbd { background: #eaeaea; color: #333; font-size: 14px;} #hover_div .score_tbd a { color: #333}.negative, .score_terrible, .score_unfavorable, .carousel_set a.product_terrible:hover, .carousel_set a.product_unfavorable:hover { background-color: #f00}.mixed, .neutral, .score_mixed, .carousel_set a.product_mixed:hover { background-color: #fc3; color: #333;} #hover_div .score_mixed a { color: #333}.positive, .score_favorable, .score_outstanding, .carousel_set a.product_favorable:hover, .carousel_set a.product_outstanding:hover { background-color: #6c3}.critscore_terrible, .critscore_unfavorable { border-color: #f00}.critscore_mixed { border-color: #fc3}.critscore_favorable, .critscore_outstanding { border-color: #6c3}.metascore .score_total, .userscore .score_total { display: none; visibility: hidden;}.hoverinfo .metascore_label, .hoverinfo .userscore_label { font-size: 12px; font-weight: bold; line-height: 16px; margin-top: 2%;}.hoverinfo .metascore_review_count, .hoverinfo .userscore_review_count { font-size: 11px}.hoverinfo .hover_scores td { vertical-align: middle}.hoverinfo .hover_scores td.num { width: 39px}.hoverinfo .hover_scores td.usr.num { padding-left: 20px}.metascore_anchor, a.metascore_w { text-decoration: none !important} .metascore_w.album { padding-top:0px; !important} .metascore_w.user { border-radius: 55%; color: #fff;}.metascore_anchor, .metascore_w.album { padding: 0px;!important, padding-top: 0px;!important} a.metascore_w { text-decoration: none!important}.metascore_anchor:hover { text-decoration: none!important}.metascore_w:hover { text-decoration: none!important}span.metascore_w, a.metascore_w { display: inline-block}.metascore_w.xlarge, .metascore_w.xl { font-size: 42px}.metascore_w.large, .metascore_w.lrg { font-size: 25px}.m .metascore_w.medium, .m .metascore_w.med { font-size: 19px}.metascore_w.med_small { font-size: 14px}.metascore_w.small, .metascore_w.sm { font-size: 12px}.metascore_w.tiny { height: 1.9em; font-size: 11px; line-height: 1.9em;}.metascore_w.user { border-radius: 55%; color: #fff;}.metascore_w.user.small, .metascore_w.user.sm { font-size: 11px}.metascore_w.tbd, .metascore_w.score_tbd { color: #000!important; background-color: #ccc;}.metascore_w.tbd.hide_tbd, .metascore_w.score_tbd.hide_tbd { visibility: hidden}.metascore_w.tbd.no_tbd, .metascore_w.score_tbd.no_tbd { display: none}.metascore_w.noscore::before, .metascore_w.score_noscore::before { content: '\2022\2022\2022'}.metascore_w.noscore, .metascore_w.score_noscore { color: #fff!important; background-color: #ccc;}.metascore_w.rip, .metascore_w.score_rip { border-radius: 4px; color: #fff!important; background-color: #999;}.metascore_w.negative, .metascore_w.score_terrible, .metascore_w.score_unfavorable { background-color: #f00}.metascore_w.mixed, .metascore_w.forty, .metascore_w.game.fifty, .metascore_w.score_mixed { background-color: #fc3}.metascore_w.positive, .metascore_w.sixtyone, .metascore_w.game.seventyfive, .metascore_w.score_favorable, .metascore_w.score_outstanding { background-color: #6c3}.metascore_w.indiv { height: 1.9em; width: 1.9em; font-size: 15px; line-height: 1.9em;}.metascore_w.indiv.large, .metascore_w.indiv.lrg { font-size: 24px}.m .metascore_w.indiv.medium, .m .metascore_w.indiv.med { font-size: 16px}.metascore_w.indiv.small, .metascore_w.indiv.sm { font-size: 11px}.metascore_w.indiv.perfect { padding-right: 1px}.promo_amazon .esite_btn { margin: 3px 0 0 7px;}.esite_amazon { background-color: #fdc354; border: 1px solid #aaa;}.esite_label_wrapper { display:none;}.esite_btn { border-radius: 4px; color: #222; font-size: 12px; height: 40px; line-height: 40px; width: 120px;} .chart{background-color:inherit!important;margin-top:-3px} .chart_bg{width:100%;border-top:3px solid rgba(150,150,150,0.3)} .chart .bar{width:100%;height:3px} .chart .count{font-size:10px}";
  948.  
  949. var framesrc = 'data:text/html,';
  950. framesrc += encodeURIComponent('<!DOCTYPE html>\
  951. <html lang="en">\
  952. <head>\
  953. <meta charset="utf-8">\
  954. <title>Metacritic info</title>\
  955. <style>body { margin:0px; padding:0px; background:white; }' + css
  956. +'\
  957. </style>\
  958. <script>\
  959. var failedImages = {};\
  960. function detectCSP(img) {\
  961. if(img.complete && (!img.naturalWidth || !img.naturalHeight)) {\
  962. return true;\
  963. }\
  964. return false;\
  965. }\
  966. function findCSPerrors() {\
  967. var imgs = document.querySelectorAll("img");\
  968. for(var i = 0; i < imgs.length; i++) {\
  969. if(imgs[i].complete && detectCSP(imgs[i])) {\
  970. fixCSP(imgs[i]);\
  971. }\
  972. }\
  973. }\
  974. function fixCSP(img) {\
  975. console.log("Loading image failed. Bypassing CSP...");\
  976. failedImages[img.src] = img;\
  977. parent.postMessage({"mcimessage_loadImg":true, "mcimessage_imgUrl": img.src},"*"); \
  978. }\
  979. function on_load() {\
  980. ('+functions.frame.toString()+')();\
  981. window.setTimeout(findCSPerrors, 500);\
  982. }\
  983. </script>\
  984. </head>\
  985. <body onload="on_load();">\
  986. <div style="border:0px solid; display:block; position:relative; border-radius:0px; padding:0px; margin:0px; box-shadow:none;" class="hover_div" id="hover_div">\
  987. <div class="hover_content">'+fixMetacriticURLs(html)+'</div>\
  988. </div>\
  989. </body>\
  990. </html>');
  991.  
  992. var frame = $("<iframe></iframe>").appendTo(div);
  993. frame.attr("id","mciframe123");
  994. frame.attr("src",framesrc);
  995. frame.attr("scrolling","auto");
  996. frame.css({
  997. width: 380,
  998. height: 150,
  999. border: "none"
  1000. });
  1001.  
  1002. window.setTimeout(function() {
  1003. if(!frame_status) { // Loading frame content failed.
  1004. // Directly inject the html without an iframe (this may break the site or the metacritic)
  1005. console.log("Loading iframe content failed. Injecting directly.");
  1006. $("head").append("<style>"+css+"</style>");
  1007. var noframe = $('<div style="border:0px solid; display:block; position:relative; border-radius:0px; padding:0px; margin:0px; box-shadow:none;" class="hover_div" id="hover_div">\
  1008. <div class="hover_content">'+fixMetacriticURLs(html)+'</div>\
  1009. </div>');
  1010. frame.replaceWith(noframe);
  1011. }
  1012.  
  1013. },2000);
  1014.  
  1015. functions.parent();
  1016.  
  1017. var sub = $("<div></div>").appendTo(div);
  1018. $('<time style="color:#b6b6b6; font-size: 11px;" datetime="'+time+'" title="'+time.toLocaleTimeString()+" "+time.toLocaleDateString()+'">'+minutesSince(time)+'</time>').appendTo(sub);
  1019. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="'+url+'" title="Open Metacritic">'+decodeURI(url.replace("https://www.","@"))+'</a>').appendTo(sub);
  1020. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px; padding-left:5px;">&#10062;</span>').appendTo(sub).click(function() {
  1021. document.body.removeChild(this.parentNode.parentNode);
  1022. });
  1023.  
  1024. $('<span title="Assist us: This is the correct entry!" style="cursor:pointer; float:right; color:green; font-size: 11px;">&check;</span>').data("url", url).appendTo(sub).click(function() {
  1025. var docurl = document.location.href;
  1026. var metaurl = $(this).data("url");
  1027. var r = addToMap(docurl,metaurl);
  1028. balloonAlert("Thanks for your submission!\n\nSaved as a correct entry.\n\n"+r[0]+"\n"+r[1], 6000, "Success");
  1029. });
  1030. $('<span title="Assist us: This is NOT the correct entry!" style="cursor:pointer; float:right; color:crimson; font-size: 11px;">&cross;</span>').data("url", url).appendTo(sub).click(function() {
  1031. if(!confirm("This is NOT the correct entry!\n\nAdd to blacklist?")) return;
  1032. var docurl = document.location.href;
  1033. var metaurl = $(this).data("url");
  1034. var r = addToBlacklist(docurl,metaurl);
  1035. balloonAlert("Thanks for your submission!\n\nSaved to blacklist.\n\n"+r[0]+"\n"+r[1], 6000, "Success");
  1036.  
  1037. // Open search
  1038. metacritic_searchcontainer(null, current.searchTerm);
  1039. metacritic_search(null, current.searchTerm);
  1040. });
  1041.  
  1042.  
  1043.  
  1044. },
  1045. // On error i.e. no result on metacritic.com
  1046. function(html, time) {
  1047.  
  1048. // Make search available
  1049. metacritic_waitForHotkeys();
  1050.  
  1051. var handleresponse = function(response) {
  1052. var data;
  1053. var multiple = false;
  1054. try {
  1055. data = JSON.parse(response.responseText);
  1056. } catch(e) {
  1057. console.log("Error in JSON 05: search_term="+current.searchTerm);
  1058. console.log(e);
  1059. }
  1060. if(data && data.autoComplete && data.autoComplete.results && data.autoComplete.results.length) {
  1061. // Remove data with wrong type
  1062.  
  1063. data.autoComplete = data.autoComplete.results;
  1064.  
  1065. var newdata = [];
  1066. data.autoComplete.forEach(function(result) {
  1067. if(metacritic2searchType(result.refType) == current.type) {
  1068. newdata.push(result);
  1069. }
  1070. });
  1071. data.autoComplete = newdata;
  1072. if(data.autoComplete.length == 0) {
  1073. // No results
  1074. console.log("No results (after filtering by type) for search_term="+current.searchTerm);
  1075. } else if(data.autoComplete.length == 1) {
  1076. // One result, let's show it
  1077. console.log("Only one exact match for search_term="+current.searchTerm);
  1078. if(!isBlacklisted(absoluteMetaURL(data.autoComplete[0].url))) {
  1079. metacritic_showHoverInfo(absoluteMetaURL(data.autoComplete[0].url));
  1080. return;
  1081. }
  1082. } else {
  1083. // More than one result
  1084. multiple = true;
  1085. console.log("Multiple results for search_term="+current.searchTerm);
  1086. var exactMatches = [];
  1087. data.autoComplete.forEach(function(result,i) { // Try to find the correct result by matching the search term to exactly one movie title
  1088. if(current.searchTerm == result.name) {
  1089. exactMatches.push(result);
  1090. }
  1091. });
  1092. if(exactMatches.length == 1) {
  1093. // Only one exact match, let's show it
  1094. console.log("Only one exact match for search_term="+current.searchTerm);
  1095. if(!isBlacklisted(absoluteMetaURL(exactMatches[0].url))) {
  1096. if( url != absoluteMetaURL(exactMatches[0].url)) {
  1097. metacritic_showHoverInfo(absoluteMetaURL(exactMatches[0].url));
  1098. } else {
  1099. console.log("Loop detected for: "+url);
  1100. }
  1101. return;
  1102. }
  1103. }
  1104. }
  1105. } else {
  1106. console.log("No results (at all) for search_term="+current.searchTerm);
  1107. }
  1108. // HERE: multiple results or no result. The user may type "meta" now
  1109. if(multiple) {
  1110. balloonAlert("Multiple metacritic results. Type &#34;meta&#34; for manual search.", 10000, false, {bottom: 5, top:"auto", maxWidth: 400, paddingRight: 5}, metacritic_searchcontainer);
  1111. }
  1112. };
  1113. var cache = JSON.parse(GM_getValue("autosearchcache","{}"));
  1114. for(var prop in cache) {
  1115. // Delete cached values, that are older than 2 hours
  1116. if((new Date()).getTime() - (new Date(cache[prop].time)).getTime() > 2*60*60*1000) {
  1117. delete cache[prop];
  1118. }
  1119. }
  1120.  
  1121. if(current.type == "music") {
  1122. current.searchTerm = current.data[0];
  1123. } else {
  1124. current.searchTerm = current.data.join(" ");
  1125. }
  1126.  
  1127. if(current.searchTerm in cache) {
  1128. handleresponse(cache[current.searchTerm], true);
  1129. } else {
  1130. GM_xmlhttpRequest({
  1131. method: "POST",
  1132. url: baseURL_autosearch,
  1133. data: "search_term="+encodeURIComponent(current.searchTerm)+"&image_size=98&search_each=1&sort_type=popular",
  1134. headers: {
  1135. "Referer" : url,
  1136. "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8",
  1137. "Host" : "www.metacritic.com",
  1138. "User-Agent" : "MetacriticUserscript Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0",
  1139. "X-Requested-With" : "XMLHttpRequest"
  1140. },
  1141. onload: function(response) {
  1142.  
  1143. response = {
  1144. time : (new Date()).toJSON(),
  1145. responseText : response.responseText,
  1146. };
  1147. cache[current.searchTerm] = response;
  1148. GM_setValue("autosearchcache",JSON.stringify(cache));
  1149. handleresponse(response, false);
  1150. }
  1151. });
  1152. }
  1153. });
  1154. }
  1155.  
  1156. function metacritic_waitForHotkeys() {
  1157. listenForHotkeys("meta",metacritic_searchcontainer);
  1158. }
  1159.  
  1160. function metacritic_searchcontainer(ev, query) {
  1161. if(!query) {
  1162. if(current.type == "music") {
  1163. query = current.data[0];
  1164. } else {
  1165. query = current.data.join(" ");
  1166. }
  1167. }
  1168. $("#mcdiv123").remove();
  1169. var div = $('<div id="mcdiv123"></div>').appendTo(document.body);
  1170. div.css({
  1171. position:"fixed",
  1172. bottom :0,
  1173. left: 0,
  1174. minWidth: 300,
  1175. maxHeight: "80%",
  1176. maxWidth: 640,
  1177. overflow:"auto",
  1178. backgroundColor: "#fff",
  1179. border: "2px solid #bbb",
  1180. borderRadius:" 6px",
  1181. boxShadow: "0 0 3px 3px rgba(100, 100, 100, 0.2)",
  1182. color: "#000",
  1183. padding:" 3px",
  1184. zIndex: "5010001",
  1185. });
  1186. var query = $('<input type="text" size="60" id="mcisearchquery" style="background:white;color:black;">').appendTo(div).focus().val(query).on('keypress', function(e) {
  1187. var code = e.keyCode || e.which;
  1188. if(code == 13) { // Enter key
  1189. metacritic_search.call(this,e);
  1190. }
  1191. });
  1192. $('<button id="mcisearchbutton" style="background:silver;color:black;">').text("Search").appendTo(div).click(metacritic_search);
  1193. }
  1194.  
  1195.  
  1196. function metacritic_search(ev, query) {
  1197. if(!query) { // Use values from search form
  1198. query = $("#mcisearchquery").val();
  1199. }
  1200. var type = searchType2metacritic(current.type);
  1201.  
  1202. var style = document.createElement('style');
  1203. style.type = 'text/css';
  1204. style.innerHTML = CSS;
  1205. document.head.appendChild(style);
  1206.  
  1207. var div = $("#mcdiv123");
  1208. var loader = $('<div style="width:20px; height:20px;" class="grespinner"></div>').appendTo($("#mcisearchbutton"));
  1209.  
  1210. var url = baseURL_search.replace("{type}",encodeURIComponent(type)).replace("{query}",encodeURIComponent(query));
  1211. metacritic_searchResults(url,
  1212. // On success
  1213. function(results, time) {
  1214. loader.remove();
  1215.  
  1216. var accept = function(ev) {
  1217. var a = $(this.parentNode).find("a[href*='metacritic.com']");
  1218. var metaurl = a.attr("href");
  1219.  
  1220. var docurl = document.location.href;
  1221.  
  1222. addToMap(docurl,metaurl);
  1223.  
  1224. metacritic_showHoverInfo(metaurl);
  1225. };
  1226. var denyAll = function(ev) {
  1227. var urls = [];
  1228. var docurl = document.location.href;
  1229. $("#mcdiv123searchresults").find("div.result a[href*='metacritic.com']").each(function() {
  1230. addToBlacklist(docurl, this.href);
  1231. });
  1232. };
  1233.  
  1234. var resultdiv = $("#mcdiv123searchresults").length?$("#mcdiv123searchresults").html(""):$('<div id="mcdiv123searchresults"></div>').css("max-width","95%").appendTo(div);
  1235. results.forEach(function(html) {
  1236. var singleresult = $('<div class="result"></div>').html(fixMetacriticURLs(html)+'<div style="clear:left"></div>').appendTo(resultdiv);
  1237. $('<span title="Assist us: This is the correct entry!" style="cursor:pointer; color:green; font-size: 13px;">&check;</span>').prependTo(singleresult).click(accept);
  1238. });
  1239. resultdiv.find(".metascore_w.album").removeClass("album"); // Remove some classes
  1240.  
  1241. var sub = $("<div></div>").appendTo(div);
  1242. $('<time style="color:#b6b6b6; font-size: 11px;" datetime="'+time+'" title="'+time.toLocaleDateString()+'">'+minutesSince(time)+'</time>').appendTo(sub);
  1243. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="'+url+'" title="Open Metacritic">'+decodeURI(url.replace("https://www.","@"))+'</a>').appendTo(sub);
  1244. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px;">&#10062;</span>').appendTo(sub).click(function() {
  1245. document.body.removeChild(this.parentNode.parentNode);
  1246. });
  1247. $('<span title="Assist us: None of the above is the correct item!" style="cursor:pointer; float:right; color:crimson; font-size: 11px;">&cross;</span>').appendTo(sub).click(function() {if(confirm("None of the above is the correct item\nConfirm?")) denyAll()});
  1248. },
  1249. // On error i.e. no results
  1250. function(results, time) {
  1251. loader.remove();
  1252. var resultdiv = $("#mcdiv123searchresults").length?$("#mcdiv123searchresults").html(""):$('<div id="mcdiv123searchresults"></div>').appendTo(div);
  1253. resultdiv.html("No search results.");
  1254.  
  1255. var sub = $("<div></div>").appendTo(div);
  1256. $('<time style="color:#b6b6b6; font-size: 11px;" datetime="'+time+'" title="'+time.toLocaleDateString()+'">'+minutesSince(time)+'</time>').appendTo(sub);
  1257. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="'+url+'" title="Open Metacritic">'+decodeURI(url.replace("https://www.","@"))+'</a>').appendTo(sub);
  1258. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px;">&#10062;</span>').appendTo(sub).click(function() {
  1259. document.body.removeChild(this.parentNode.parentNode);
  1260. });
  1261.  
  1262. }
  1263. );
  1264. }
  1265.  
  1266. var current = {
  1267. url : null,
  1268. type : null,
  1269. data : null, // Array of raw search keys
  1270. searchTerm : null
  1271. };
  1272.  
  1273.  
  1274. function showURL(url) {
  1275. if(!isBlacklisted(url)) {
  1276. var docurl = document.location.host.replace(/^www\./,"") + document.location.pathname + document.location.search;
  1277. docurl = filterUniversalUrl(docurl);
  1278. metacritic_showHoverInfo(url, docurl);
  1279. } else {
  1280. console.log(url +" is blacklisted!");
  1281. }
  1282. }
  1283.  
  1284.  
  1285. var metacritic = {
  1286. "mapped" : function metacritic_mapped(url, type) {
  1287. // url was in the map/whitelist
  1288. current.data = [url]
  1289. current.url = url;
  1290. current.type = type;
  1291. current.searchTerm = url;
  1292. showURL(url);
  1293. },
  1294. "music" : function metacritic_music(artistname, albumname) {
  1295. current.data = [albumname.trim(),artistname.trim()]
  1296. artistname = name2metacritic(artistname);
  1297. albumname = albumname.replace("&"," ");
  1298. albumname = name2metacritic(albumname);
  1299. var url = baseURL_music + albumname + "/" + artistname;
  1300. current.url = url;
  1301. current.type = "music";
  1302. current.searchTerm = albumname + "/" + artistname;
  1303. showURL(url);
  1304. },
  1305. "movie" : function metacritic_movie(moviename) {
  1306. current.data = [moviename.trim()]
  1307. moviename = name2metacritic(moviename);
  1308. var url = baseURL_movie + moviename;
  1309. current.url = url;
  1310. current.type = "movie";
  1311. current.searchTerm = moviename;
  1312. showURL(url);
  1313. },
  1314. "tv" : function metacritic_tv(seriesname) {
  1315. current.data = [seriesname.trim()]
  1316. seriesname = name2metacritic(seriesname);
  1317. var url = baseURL_tv + seriesname;
  1318. current.url = url;
  1319. current.type = "tv";
  1320. current.searchTerm = seriesname;
  1321. showURL(url);
  1322. },
  1323. "pcgame" : function metacritic_pcgame(gamename) {
  1324. current.data = [gamename.trim()]
  1325. gamename = name2metacritic(gamename);
  1326. var url = baseURL_pcgame + gamename;
  1327. current.url = url;
  1328. current.type = "pcgame";
  1329. current.searchTerm = gamename;
  1330. showURL(url);
  1331. },
  1332. "ps4game" : function metacritic_ps4game(gamename) {
  1333. current.data = [gamename.trim()]
  1334. gamename = name2metacritic(gamename);
  1335. var url = baseURL_ps4 + gamename;
  1336. current.url = url;
  1337. current.type = "ps4game";
  1338. current.searchTerm = gamename;
  1339. showURL(url);
  1340. },
  1341. "xonegame" : function metacritic_xonegame(gamename) {
  1342. current.data = [gamename.trim()]
  1343. gamename = name2metacritic(gamename);
  1344. var url = baseURL_xone + gamename;
  1345. current.url = url;
  1346. current.type = "xonegame";
  1347. current.searchTerm = gamename;
  1348. showURL(url);
  1349. }
  1350. };
  1351.  
  1352.  
  1353. var Always = function() { return true; };
  1354. var sites = {
  1355. 'bandcamp' : {
  1356. host : ["bandcamp.com"],
  1357. condition : function() {
  1358. return unsafeWindow.TralbumData
  1359. },
  1360. products : [{
  1361. condition : Always,
  1362. type : "music",
  1363. data : function() { return [unsafeWindow.TralbumData.artist, unsafeWindow.TralbumData.current.title]; }
  1364. }]
  1365. },
  1366. 'itunes' : {
  1367. host : ["itunes.apple.com"],
  1368. condition : Always,
  1369. products : [{
  1370. condition : function() { return ~document.location.href.indexOf("/movie/")},
  1371. type : "movie",
  1372. data : function() { return parseLDJSON("name", function(j) {return j["@type"] == "Movie"} )}
  1373. },
  1374. {
  1375. condition : function() { return ~document.location.href.indexOf("/tv-season/")},
  1376. type : "tv",
  1377. data : function() {
  1378. var name = parseLDJSON("name", function(j) {return j["@type"] == "TVSeries"});
  1379. if(~name.indexOf(", Season")) {
  1380. name = name.split(", Season")[0];
  1381. }
  1382. return name;
  1383. }
  1384. },
  1385. {
  1386. condition : function() { return ~document.location.href.indexOf("/album/")},
  1387. type : "music",
  1388. data : function() {
  1389. var ld = parseLDJSON(["name","byArtist"], function(j) {return j["@type"] == "MusicAlbum"});
  1390. var album = ld[0];
  1391. var artist = ld[1]["name"]
  1392. return [artist, album];
  1393. }
  1394. }]
  1395. },
  1396. 'music.apple' : {
  1397. host : ["music.apple.com"],
  1398. condition : Always,
  1399. products : [{
  1400. condition : function() { return ~document.location.href.indexOf("/album/")},
  1401. type : "music",
  1402. data : function() {
  1403. var ld = parseLDJSON(["name","byArtist"], function(j) {return j["@type"] == "MusicAlbum"});
  1404. var album = ld[0];
  1405. var artist = ld[1]["name"]
  1406. return [artist, album];
  1407. }
  1408. }]
  1409. },
  1410. 'googleplay' : {
  1411. host : ["play.google.com"],
  1412. condition : Always,
  1413. products : [
  1414. {
  1415. condition : function() { return ~document.location.href.indexOf("/album/")},
  1416. type : "music",
  1417. data : function() { return [document.querySelector('[itemprop="byArtist"] meta[itemprop="name"]').content, document.querySelector('[itemtype="https://schema.org/MusicAlbum"] meta[itemprop="name"]').content]}
  1418. },
  1419. {
  1420. condition : function() { return ~document.location.href.indexOf("/movies/details/")},
  1421. type : "movie",
  1422. data : function() { return document.querySelector("*[itemprop=name]").textContentt}
  1423. }
  1424. ]
  1425. },
  1426. 'imdb' : {
  1427. host : ["imdb.com"],
  1428. condition : function() {
  1429. return !~document.location.pathname.indexOf("/mediaviewer") && !~document.location.pathname.indexOf("/mediaindex") && !~document.location.pathname.indexOf("/videoplayer");
  1430. },
  1431. products : [
  1432. {
  1433. condition : function() {
  1434. var e = document.querySelector("meta[property='og:type']");
  1435. if(e) {
  1436. return e.content == "video.movie"
  1437. }
  1438. return false;
  1439. },
  1440. type : "movie",
  1441. data : function() {
  1442. if(document.querySelector("meta[property='og:title']") && document.querySelector("meta[property='og:title']").content) { // English/Worldwide title, this is the prefered title for search
  1443. name = document.querySelector("meta[property='og:title']").content.trim()
  1444. if (name.indexOf('- IMDb') !== -1) {
  1445. name = name.replace('- IMDb', '').trim()
  1446. }
  1447. name = name.replace(/\(\d{4}\)/, '').trim()
  1448. return name
  1449. } else if(document.querySelector(".originalTitle") && document.querySelector(".title_wrapper h1")) { // Use English title 2018
  1450. return document.querySelector(".title_wrapper h1").firstChild.data.trim();
  1451. } else if(document.querySelector('script[type="application/ld+json"]')) { // Use original language title
  1452. return parseLDJSON("name");
  1453. } else if(document.querySelector("h1[itemprop=name]")) { // Movie homepage (New design 2015-12)
  1454. return document.querySelector("h1[itemprop=name]").firstChild.textContent.trim();
  1455. } else if(document.querySelector("*[itemprop=name] a") && document.querySelector("*[itemprop=name] a").firstChild.data) { // Subpage of a move
  1456. return document.querySelector("*[itemprop=name] a").firstChild.data.trim();
  1457. } else if(document.querySelector(".title-extra[itemprop=name]")) { // Movie homepage: sub-/alternative-/original title
  1458. return document.querySelector(".title-extra[itemprop=name]").firstChild.textContent.replace(/\"/g,"").trim();
  1459. } else { // Movie homepage (old design)
  1460. return document.querySelector("*[itemprop=name]").firstChild.textContent.trim();
  1461. }
  1462. }
  1463. },
  1464. {
  1465. condition : function() {
  1466. var e = document.querySelector("meta[property='og:type']");
  1467. if(e) {
  1468. return e.content == "video.tv_show"
  1469. }
  1470. return false;
  1471. },
  1472. type : "tv",
  1473. data : function() {
  1474. var year = null;
  1475. if(document.querySelector("*[itemprop=name]")) {
  1476. return document.querySelector("*[itemprop=name]").textContent;
  1477. } else {
  1478. var jsonld = JSON.parse(document.querySelector('script[type="application/ld+json"]').innerText);
  1479. return jsonld["name"];
  1480. }
  1481. }
  1482. }
  1483. ]
  1484. },
  1485. 'steam' : {
  1486. host : ["store.steampowered.com"],
  1487. condition : function() { return document.querySelector("*[itemprop=name]")},
  1488. products : [{
  1489. condition : Always,
  1490. type : "pcgame",
  1491. data : function() { return document.querySelector("*[itemprop=name]").textContent}
  1492. }]
  1493. },
  1494. 'tv.com' : {
  1495. host : ["www.tv.com"],
  1496. condition : function() { return document.querySelector("meta[property='og:type']") },
  1497. products : [{
  1498. condition : function() { return document.querySelector("meta[property='og:type']").content == "tv_show" && document.querySelector("h1[data-name]") },
  1499. type : "tv",
  1500. data : function() { return document.querySelector("h1[data-name]").dataset.name }
  1501. }]
  1502. },
  1503. 'rottentomatoes' : {
  1504. host : ["www.rottentomatoes.com"],
  1505. condition : Always,
  1506. products : [{
  1507. condition : function() { return document.location.pathname.startsWith("/m/")},
  1508. type : "movie",
  1509. data : function() { return document.querySelector("h1").firstChild.textContent}
  1510. },
  1511. {
  1512. condition : function() { return document.location.pathname.startsWith("/tv/")} ,
  1513. type : "tv",
  1514. data : function() { return unsafeWindow.BK.TvSeriesTitle}
  1515. }
  1516. ]
  1517. },
  1518. 'serienjunkies' : {
  1519. host : ["www.serienjunkies.de"],
  1520. condition : Always,
  1521. products : [{
  1522. condition : Always,
  1523. type : "tv",
  1524. data : function() {
  1525. return parseLDJSON("name", function(j) { return j["@type"] == "TVSeries"; });
  1526. }
  1527. }]
  1528. },
  1529. 'gamespot' : {
  1530. host : ["gamespot.com"],
  1531. condition : function() { return document.querySelector("[itemprop=device]")},
  1532. products : [
  1533. {
  1534. condition : function() { return ~$("[itemprop=device]").text().indexOf("PC")},
  1535. type : "pcgame",
  1536. data : function() { return parseLDJSON("name", function(j) { return j["@type"] == "VideoGame"; }); }
  1537. },
  1538. {
  1539. condition : function() { return ~$("[itemprop=device]").text().indexOf("PS4")},
  1540. type : "ps4game",
  1541. data : function() { return parseLDJSON("name", function(j) { return j["@type"] == "VideoGame"; }); }
  1542. },
  1543. {
  1544. condition : function() { return ~$("[itemprop=device]").text().indexOf("XONE")},
  1545. type : "xonegame",
  1546. data : function() { return parseLDJSON("name", function(j) { return j["@type"] == "VideoGame"; }); }
  1547. }
  1548. ]
  1549. },
  1550. 'amazon' : {
  1551. host : ["amazon."],
  1552. condition : Always,
  1553. products : [
  1554. {
  1555. condition : function() { return document.location.hostname == "music.amazon.com" && document.location.pathname.startsWith("/albums/") && document.querySelector(".viewTitle") }, // "Amazon Music Unlimited" page
  1556. type : "music",
  1557. data : function() {
  1558. var artist = document.querySelector(".artistLink").textContent.trim();
  1559. var title = document.querySelector(".viewTitle").textContent.trim();
  1560. title = title.replace(/\[([^\]]*)\]/g,"").trim(); // Remove [brackets] and their content
  1561. if(artist && title) {
  1562. return [artist, title];
  1563. }
  1564. return false;
  1565. }
  1566. },
  1567. {
  1568. condition : function() { // "Normal amazon" page
  1569. try {
  1570. if(document.querySelector(".nav-categ-image").alt.toLowerCase().indexOf("musi") != -1) {
  1571. return true;
  1572. }
  1573. } catch(e) {}
  1574. var music = ["Music","Musique","Musik","Música","Musica","音楽"];
  1575. return music.some(function(s) {
  1576. if(~document.title.indexOf(s)) {
  1577. return true;
  1578. } else {
  1579. return false;
  1580. }
  1581. });
  1582. },
  1583. type : "music",
  1584. data : function() {
  1585. var artist = document.querySelector("#ProductInfoArtistLink").textContent.trim();
  1586. var title = document.querySelector("#dmusicProductTitle_feature_div").textContent.trim();
  1587. title = title.replace(/\[([^\]]*)\]/g,"").trim(); // Remove [brackets] and their content
  1588. return [artist, title];
  1589. }
  1590. },
  1591. {
  1592. condition : function() { return document.querySelector('[data-automation-id=title]') && (document.getElementsByClassName("av-season-single").length || document.querySelector('[data-automation-id="num-of-seasons-badge"]'))},
  1593. type : "tv",
  1594. data : function() { return document.querySelector('[data-automation-id=title]').textContent.trim()}
  1595. },
  1596. {
  1597. condition : function() { return document.querySelector('[data-automation-id=title]')},
  1598. type : "movie",
  1599. data : function() { return document.querySelector('[data-automation-id=title]').textContent.trim()}
  1600. }
  1601. ]
  1602. },
  1603. 'BoxOfficeMojo' : {
  1604. host : ["boxofficemojo.com"],
  1605. condition : function() { return ~document.location.search.indexOf("id=")},
  1606. products : [{
  1607. condition : function() { return document.querySelector("#body table:nth-child(2) tr:first-child b")},
  1608. type : "movie",
  1609. data : function() { return document.querySelector("#body table:nth-child(2) tr:first-child b").firstChild.data}
  1610. }]
  1611. },
  1612. 'AllMovie' : {
  1613. host : ["allmovie.com"],
  1614. condition : function() { return document.querySelector("h2[itemprop=name].movie-title")},
  1615. products : [{
  1616. condition : function() { return document.querySelector("h2[itemprop=name].movie-title")},
  1617. type : "movie",
  1618. data : function() { return document.querySelector("h2[itemprop=name].movie-title").firstChild.data.trim()}
  1619. }]
  1620. },
  1621. 'en.wikipedia' : {
  1622. host : ["en.wikipedia.org"],
  1623. condition : Always,
  1624. products : [{
  1625. condition : function() {
  1626. if(!document.querySelector(".infobox .summary")) {
  1627. return false;
  1628. }
  1629. var r = /\d\d\d\d films/;
  1630. return $("#catlinks a").filter(function(i,e) {return e.firstChild.data.match(r)}).length;
  1631. },
  1632. type : "movie",
  1633. data : function() { return document.querySelector(".infobox .summary").firstChild.data}
  1634. },
  1635. {
  1636. condition : function() {
  1637. if(!document.querySelector(".infobox .summary")) {
  1638. return false;
  1639. }
  1640. var r = /television series/;
  1641. return $("#catlinks a").filter(function(i,e) {return e.firstChild.data.match(r)}).length;
  1642. },
  1643. type : "tv",
  1644. data : function() { return document.querySelector(".infobox .summary").firstChild.data}
  1645. }]
  1646. },
  1647. 'movies.com' : {
  1648. host : ["movies.com"],
  1649. condition : function() { return document.querySelector("meta[property='og:title']")},
  1650. products : [{
  1651. condition : Always,
  1652. type : "movie",
  1653. data : function() { return document.querySelector("meta[property='og:title']").content}
  1654. }]
  1655. },
  1656. 'themoviedb' : {
  1657. host : ["themoviedb.org"],
  1658. condition : function() { return document.querySelector("meta[property='og:type']")},
  1659. products : [{
  1660. condition : function() { return document.querySelector("meta[property='og:type']").content == "movie"},
  1661. type : "movie",
  1662. data : function() { return document.querySelector("meta[property='og:title']").content}
  1663. },
  1664. {
  1665. condition : function() { return document.querySelector("meta[property='og:type']").content == "tv_series"},
  1666. type : "tv",
  1667. data : function() { return document.querySelector("meta[property='og:title']").content}
  1668. }]
  1669. },
  1670. 'letterboxd' : {
  1671. host : ["letterboxd.com"],
  1672. condition : function() { return unsafeWindow.filmData && "name" in unsafeWindow.filmData},
  1673. products : [{
  1674. condition : Always,
  1675. type : "movie",
  1676. data : function() { return unsafeWindow.filmData.name}
  1677. }]
  1678. },
  1679. 'TVmaze' : {
  1680. host : ["tvmaze.com"],
  1681. condition : function() { return document.querySelector("h1")},
  1682. products : [{
  1683. condition : Always,
  1684. type : "tv",
  1685. data : function() { return document.querySelector("h1").firstChild.data}
  1686. }]
  1687. },
  1688. 'TVGuide' : {
  1689. host : ["tvguide.com"],
  1690. condition : Always,
  1691. products : [{
  1692. condition : function() { return document.location.pathname.startsWith("/tvshows/")},
  1693. type : "tv",
  1694. data : function() {
  1695. if(document.querySelector("meta[itemprop=name]")) {
  1696. return document.querySelector("meta[itemprop=name]").content;
  1697. } else {
  1698. return document.querySelector("meta[property='og:title']").content.split("|")[0];
  1699. }
  1700. }
  1701. }]
  1702. },
  1703. 'followshows' : {
  1704. host : ["followshows.com"],
  1705. condition : Always,
  1706. products : [{
  1707. condition : function() { return document.querySelector("meta[property='og:type']").content == "video.tv_show"},
  1708. type : "tv",
  1709. data : function() { return document.querySelector("meta[property='og:title']").content}
  1710. }]
  1711. },
  1712. 'TheTVDB' : {
  1713. host : ["thetvdb.com"],
  1714. condition : Always,
  1715. products : [{
  1716. condition : function() { return document.location.pathname.startsWith("/series/") || ~document.location.search.indexOf("tab=series") },
  1717. type : "tv",
  1718. data : function() { return document.getElementById("series_title").firstChild.data.trim() }
  1719. }]
  1720. },
  1721. 'ConsequenceOfSound' : {
  1722. host : ["consequenceofsound.net"],
  1723. condition : function() { return document.querySelector("#main-content .review-summary") },
  1724. products : [{
  1725. condition : function() { return document.title.match(/(.+?)\s+\u2013\s+(.+?) \| Album Review/) },
  1726. type : "music",
  1727. data : function() {
  1728. let m = document.title.match(/(.+?)\s+\u2013\s+(.+?) \| Album Review/)
  1729. return [m[1], m[2]]
  1730. }
  1731. }]
  1732. },
  1733. 'Pitchfork' : {
  1734. host : ["pitchfork.com"],
  1735. condition : function() { return ~document.location.href.indexOf("/reviews/albums/") },
  1736. products : [{
  1737. condition : function() { return document.querySelector(".single-album-tombstone")},
  1738. type : "music",
  1739. data : function() {
  1740. var artist, album;
  1741. if(document.querySelector(".single-album-tombstone .artists")) {
  1742. artist = document.querySelector(".single-album-tombstone .artists").innerText.trim();
  1743. } else if(document.querySelector(".single-album-tombstone .artist-list")) {
  1744. artist = document.querySelector(".single-album-tombstone .artist-list").innerText.trim();
  1745. }
  1746. if(document.querySelector(".single-album-tombstone h1.review-title")) {
  1747. album = document.querySelector(".single-album-tombstone h1.review-title").innerText.trim();
  1748. } else if(document.querySelector(".single-album-tombstone h1")) {
  1749. album = document.querySelector(".single-album-tombstone h1").innerText.trim();
  1750. }
  1751.  
  1752. return [artist, album];
  1753. }
  1754. }]
  1755. },
  1756. 'Last.fm' : {
  1757. host : ["last.fm"],
  1758. condition :function() {return document.querySelector("*[data-page-resource-type]") && document.querySelector("*[data-page-resource-type]").dataset.pageResourceType == "album" },
  1759. products : [{
  1760. condition : function() { return document.querySelector("*[data-page-resource-type]").dataset.pageResourceName },
  1761. type : "music",
  1762. data : function() {
  1763. var artist = document.querySelector("*[data-page-resource-type]").dataset.pageResourceArtistName;
  1764. var album = document.querySelector("*[data-page-resource-type]").dataset.pageResourceName;
  1765. return [artist, album];
  1766. }
  1767. }]
  1768. },
  1769. 'TVNfo' : {
  1770. host : ["tvnfo.com"],
  1771. condition : function() {return document.querySelector("#tvsign")},
  1772. products : [{
  1773. condition : Always,
  1774. type : "tv",
  1775. data : function() {return document.querySelector(".heading h1").textContent.trim()}
  1776. }]
  1777. },
  1778. 'rateyourmusic' : {
  1779. host : ["rateyourmusic.com"],
  1780. condition :function() {return document.querySelector("meta[property='og:type']") },
  1781. products : [{
  1782. condition : function() { return document.querySelector("meta[property='og:type']").content == "music.album" },
  1783. type : "music",
  1784. data : function() {
  1785. var artist = document.querySelector(".section_main_info .artist").innerText.trim();
  1786. var album = document.querySelector(".section_main_info .album_title").innerText.trim();
  1787. return [artist, album];
  1788. }
  1789. }]
  1790. },
  1791. 'spotify_webplayer' : {
  1792. host : ["open.spotify.com"],
  1793. condition : Always,
  1794. products : [{
  1795. condition : function() {return document.querySelector("#main .main-view-container .content.album") },
  1796. type : "music",
  1797. data : function() {
  1798. var artist = document.querySelector("#main .media-bd div a[href*='artist']").textContent;
  1799. var album = document.querySelector("#main .media-bd h2").textContent;
  1800. return [artist, album];
  1801. }
  1802. },
  1803. {
  1804. condition : function() {return document.location.pathname.startsWith("/album/") && document.querySelector("meta[property='og:type']").content == "music.album" },
  1805. type : "music",
  1806. data : function() {
  1807. var artist = "";
  1808. var album = document.querySelector("meta[property='og:title']").content;
  1809. return [artist, album];
  1810. }
  1811. }]
  1812. },
  1813. 'spotify' : {
  1814. host : ["play.spotify.com"],
  1815. condition : Always,
  1816. products : [{
  1817. condition : function() {return document.location.pathname.startsWith("/album/") },
  1818. type : "music",
  1819. data : function() {
  1820. var artist = document.querySelector(".context_landing p.secondary-title").textContent;
  1821. var album = document.querySelector(".context_landing p.primary-title").textContent;
  1822. return [artist, album];
  1823. }
  1824. }]
  1825. },
  1826. 'nme' : {
  1827. host : ["nme.com"],
  1828. condition : function() {return document.location.pathname.startsWith("/reviews/") },
  1829. products : [
  1830. {
  1831. condition : function() {return document.location.pathname.startsWith("/reviews/movie/") },
  1832. type : "movie",
  1833. data : function() {
  1834. try {
  1835. return document.querySelector(".title-primary").textContent.match(/‘(.+?)’/)[1];
  1836. } catch(e) {
  1837. return document.querySelector("h1").textContent.match(/:\s*(.+)/)[1].trim();
  1838. }
  1839. }
  1840. },
  1841. {
  1842. condition : function() {return document.location.pathname.startsWith("/reviews/album/") },
  1843. type : "music",
  1844. data : function() {return document.querySelector(".title-primary").textContent.match(/\s*(.+?)\s*.\s*‘(.+?)’/).slice(1) }
  1845. }]
  1846. },
  1847. 'albumoftheyear' : {
  1848. host : ["albumoftheyear.org"],
  1849. condition : Always,
  1850. products : [{
  1851. condition : function() {return document.location.pathname.startsWith("/album/") },
  1852. type : "music",
  1853. data : function() {
  1854. var artist = document.querySelector("*[itemprop=byArtist] *[itemprop=name]").textContent;
  1855. var album = document.querySelector(".albumTitle *[itemprop=name]").textContent;
  1856. return [artist, album];
  1857. }
  1858. }]
  1859. },
  1860. 'epguides' : {
  1861. host : ['epguides.com'],
  1862. condition : function() {return document.getElementById('TVHeader')},
  1863. products : [{
  1864. condition : function() {return document.getElementById('TVHeader') && document.querySelector('body>div#header h1')},
  1865. type : 'tv',
  1866. data : function() {return document.querySelector('body>div#header h1').textContent.trim()}
  1867. }]
  1868. },
  1869. 'ShareTV' : {
  1870. host : ['sharetv.com'],
  1871. condition : function() {return document.location.pathname.startsWith("/shows/")},
  1872. products : [{
  1873. condition : function() {return document.location.pathname.split("/").length === 3 && document.querySelector("meta[property='og:title']")},
  1874. type : 'tv',
  1875. data : function() {return document.querySelector("meta[property='og:title']").content}
  1876. }]
  1877. },
  1878.  
  1879.  
  1880. };
  1881.  
  1882.  
  1883. function main() {
  1884.  
  1885. var dataFound = false;
  1886.  
  1887. var map = false;
  1888.  
  1889. for(var name in sites) {
  1890. var site = sites[name];
  1891. if(site.host.some(function(e) {return ~this.indexOf(e)}, document.location.hostname) && site.condition()) {
  1892. for(var i = 0; i < site.products.length; i++) {
  1893. if(site.products[i].condition()) {
  1894. // Check map for a match
  1895. if(map === false) {
  1896. map = JSON.parse(GM_getValue("map","{}"));
  1897. }
  1898. var docurl = document.location.host.replace(/^www\./,"") + document.location.pathname + document.location.search;
  1899. docurl = filterUniversalUrl(docurl);
  1900. if(docurl in map) {
  1901. // Found in map, show result
  1902. var metaurl = map[docurl];
  1903. metacritic["mapped"].apply(undefined, [absoluteMetaURL(metaurl), site.products[i].type]);
  1904. break;
  1905. }
  1906. // Try to retrieve item name from page
  1907. var data;
  1908. try {
  1909. data = site.products[i].data();
  1910. } catch(e) {
  1911. data = false;
  1912. console.log(e);
  1913. }
  1914. if(data) {
  1915. metacritic[site.products[i].type].apply(undefined, Array.isArray(data)?data:[data]);
  1916. dataFound = true;
  1917. }
  1918. break;
  1919. }
  1920. }
  1921. break;
  1922. }
  1923. }
  1924. return dataFound;
  1925. }
  1926.  
  1927.  
  1928. versionUpdate();
  1929. main();
  1930. var lastLoc = document.location.href;
  1931. var lastContent = document.body.innerText;
  1932. var lastCounter = 0;
  1933. function newpage() {
  1934. if(lastContent == document.body.innerText && lastCounter < 15) {
  1935. window.setTimeout(newpage, 500);
  1936. lastCounter++;
  1937. } else {
  1938. lastCounter = 0;
  1939. var re = main();
  1940. if(!re) { // No page matched or no data found
  1941. window.setTimeout(newpage, 1000);
  1942. }
  1943. }
  1944. }
  1945. window.setInterval(function() {
  1946. if(document.location.href != lastLoc) {
  1947. lastLoc = document.location.href;
  1948. $("#mcdiv123").remove();
  1949.  
  1950. window.setTimeout(newpage,1000);
  1951. }
  1952. },500);
  1953.