Show Metacritic.com ratings

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

当前为 2017-11-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Show Metacritic.com ratings
  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. // @oujs:author cuzi
  6. // @grant GM_xmlhttpRequest
  7. // @grant GM_setValue
  8. // @grant GM_getValue
  9. // @grant unsafeWindow
  10. // @require http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
  11. // @license GNUGPL
  12. // @version 26
  13. // @connect metacritic.com
  14. // @connect php-cuzi.herokuapp.com
  15. // @include https://*.bandcamp.com/*
  16. // @include https://itunes.apple.com/*/album/*
  17. // @include https://play.google.com/store/music/album/*
  18. // @include https://play.google.com/store/movies/details/*
  19. // @include http://www.amazon.com/*
  20. // @include https://www.amazon.com/*
  21. // @include http://www.amazon.co.uk/*
  22. // @include https://www.amazon.co.uk/*
  23. // @include http://www.amazon.fr/*
  24. // @include https://www.amazon.fr/*
  25. // @include http://www.amazon.de/*
  26. // @include https://www.amazon.de/*
  27. // @include http://www.amazon.es/*
  28. // @include https://www.amazon.es/*
  29. // @include http://www.amazon.ca/*
  30. // @include https://www.amazon.ca/*
  31. // @include http://www.amazon.in/*
  32. // @include https://www.amazon.in/*
  33. // @include http://www.amazon.it/*
  34. // @include https://www.amazon.it/*
  35. // @include http://www.amazon.co.jp/*
  36. // @include https://www.amazon.co.jp/*
  37. // @include http://www.amazon.com.mx/*
  38. // @include https://www.amazon.com.mx/*
  39. // @include http://www.amazon.com.au/*
  40. // @include https://www.amazon.com.au/*
  41. // @include http://www.imdb.com/title/*
  42. // @include https://www.imdb.com/title/*
  43. // @include http://store.steampowered.com/app/*
  44. // @include https://store.steampowered.com/app/*
  45. // @include http://www.gamespot.com/*
  46. // @include https://www.gamespot.com/*
  47. // @include http://www.serienjunkies.de/*
  48. // @include https://www.serienjunkies.de/*
  49. // @include http://www.tv.com/shows/*
  50. // @include http://www.rottentomatoes.com/m/*
  51. // @include https://www.rottentomatoes.com/m/*
  52. // @include http://www.rottentomatoes.com/tv/*
  53. // @include https://www.rottentomatoes.com/tv/*
  54. // @include http://www.rottentomatoes.com/tv/*/s*/
  55. // @include https://www.rottentomatoes.com/tv/*/s*/
  56. // @include http://www.boxofficemojo.com/movies/*
  57. // @include http://www.allmovie.com/movie/*
  58. // @include https://www.allmovie.com/movie/*
  59. // @include https://en.wikipedia.org/*
  60. // @include http://www.movies.com/*/m*
  61. // @include https://www.themoviedb.org/movie/*
  62. // @include https://www.themoviedb.org/tv/*
  63. // @include http://letterboxd.com/film/*
  64. // @include https://letterboxd.com/film/*
  65. // @include http://www.tvmaze.com/shows/*
  66. // @include http://www.tvguide.com/tvshows/*
  67. // @include https://www.tvguide.com/tvshows/*
  68. // @include http://followshows.com/show/*
  69. // @include https://followshows.com/show/*
  70. // @include http://thetvdb.com/*tab=series*
  71. // @include https://thetvdb.com/*tab=series*
  72. // @include http://www.thetvdb.com/*tab=series*
  73. // @include https://www.thetvdb.com/*tab=series*
  74. // @include http://consequenceofsound.net/*
  75. // @include https://consequenceofsound.net/*
  76. // @include http://pitchfork.com/*
  77. // @include https://pitchfork.com/*
  78. // @include http://www.last.fm/*
  79. // @include https://www.last.fm/*
  80. // @include http://tvnfo.com/s/*
  81. // @include http://rateyourmusic.com/release/album/*
  82. // @include https://rateyourmusic.com/release/album/*
  83. // @include https://open.spotify.com/*
  84. // @include https://play.spotify.com/album/*
  85. // ==/UserScript==
  86.  
  87.  
  88. // ########## Conversion from Script Version 15 to 16+ ######
  89. // Type of "black" value changed from {} to []
  90. if(!("length" in JSON.parse(GM_getValue("black","[]")))) {
  91. GM_setValue("black","[]");
  92. }
  93. // ########## ######
  94.  
  95.  
  96. var baseURL = "http://www.metacritic.com/";
  97.  
  98. var baseURL_music = "http://www.metacritic.com/music/";
  99. var baseURL_movie = "http://www.metacritic.com/movie/";
  100. var baseURL_pcgame = "http://www.metacritic.com/game/pc/";
  101. var baseURL_ps4 = "http://www.metacritic.com/game/playstation-4/";
  102. var baseURL_xone = "http://www.metacritic.com/game/xbox-one/";
  103. var baseURL_tv = "http://www.metacritic.com/tv/";
  104.  
  105. var baseURL_search = "http://www.metacritic.com/search/{type}/{query}/results";
  106. var baseURL_autosearch = "http://www.metacritic.com/autosearch";
  107.  
  108. var baseURL_database = "https://php-cuzi.herokuapp.com/r.php";
  109. var baseURL_whitelist = "https://php-cuzi.herokuapp.com/whitelist.php";
  110. var baseURL_blacklist = "https://php-cuzi.herokuapp.com/blacklist.php";
  111.  
  112. var mybrowser = "other";
  113. if(~navigator.userAgent.indexOf("Chrome")) {
  114. mybrowser = "chrome";
  115. }
  116.  
  117. // http://www.designcouch.com/home/why/2013/05/23/dead-simple-pure-css-loading-spinner/
  118. 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%}";
  119.  
  120. function getHostname(url) {
  121. with(document.createElement("a")) {
  122. href = url;
  123. return hostname;
  124. }
  125. }
  126. function name2metacritic(s) {
  127. return s.normalize('NFKD').replace(/\//g,"").replace(/[\u0300-\u036F]/g, '').replace(/&/g,"and").replace(/\W+/g, " ").toLowerCase().trim().replace(/\W+/g,"-");
  128. }
  129. function minutesSince(time) {
  130. var seconds = ((new Date()).getTime() - time.getTime()) / 1000;
  131. return seconds>60?parseInt(seconds/60)+" min ago":"now";
  132. }
  133. function randomStringId() {
  134. var id10 = () => Math.floor((1 + Math.random()) * 0x10000000000).toString(16).substring(1);
  135. return id10()+id10()+id10()+id10()+id10()+id10();
  136. }
  137. function fixMetacriticURLs(html) {
  138. return html.replace(/<a /g,'<a target="_blank" ').replace(/href="\//g,'href="'+baseURL).replace(/src="\//g,'src="'+baseURL);
  139. }
  140. function searchType2metacritic(type) {
  141. return ({
  142. 'movie' : 'movie',
  143. 'pcgame' : 'game',
  144. 'xonegame' : 'game',
  145. 'ps4game' : 'game',
  146. 'music' : 'album',
  147. 'tv' : 'tv'
  148. })[type];
  149. }
  150. function metacritic2searchType(type) {
  151. return ({
  152. "Album" : "music",
  153. "TV" : "tv",
  154. "Movie" : "movie",
  155. "PC Game" : "pcgame",
  156. "PS4 Game" : "ps4game",
  157. "XONE Game" : "onegame",
  158. "WIIU Game" : "xxxxx",
  159. "3DS Game" : "xxxx"
  160. })[type];
  161. }
  162.  
  163.  
  164. function metaScore(score, word) {
  165. var fg,bg,t;
  166. if(score == null) {
  167. fg = "black";
  168. bg = "#ccc";
  169. t = "tbd";
  170. } else if(score >= 75) {
  171. fg = "white";
  172. bg = "#6c3";
  173. t = parseInt(score);
  174. } else if(score < 40) {
  175. fg = "white";
  176. bg = "#f00";
  177. t = parseInt(score);
  178. } else {
  179. fg = "white";
  180. bg = "#fc3";
  181. t = parseInt(score);
  182. }
  183. 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>';
  184. }
  185.  
  186. function balloonAlert(message, timeout, title, css, click) {
  187. var header;
  188. if(title) {
  189. header = '<div style="background:rgb(220,230,150); padding: 2px 12px;">' + title +"</div>";
  190. } else if(title === false) {
  191. header = '';
  192. } else {
  193. header = '<div style="background:rgb(220,230,150); padding: 2px 12px;">Userscript alert</div>';
  194. }
  195. var div = $("<div>" + header + '<div style="padding:5px">' + message.split("\n").join("<br>") + "</div></div>");
  196. div.css({
  197. position : "fixed",
  198. top : 10,
  199. left : 10,
  200. maxWidth: 200,
  201. zIndex : "5010002",
  202. background : "rgb(240,240,240)",
  203. border : "2px solid yellow",
  204. borderRadius :"6px",
  205. boxShadow: "0 0 3px 3px rgba(100, 100, 100, 0.2)",
  206. fontFamily: "sans-serif",
  207. color: "black"
  208. });
  209. if(css) {
  210. div.css(css);
  211. }
  212. div.appendTo(document.body);
  213. if(click) {
  214. div.click(function(ev) {
  215. $(this).hide(500);
  216. click.call(this,ev);
  217. });
  218. }
  219. if(!click) {
  220. var close = $('<div title="Close" style="cursor:pointer; position:absolute; top:0px; right:3px;">&#10062;</div>').appendTo(div);
  221. close.click(function(){
  222. $(this.parentNode).hide(1000);
  223. });
  224. }
  225. if(timeout && timeout > 0) {
  226. window.setTimeout(function() {
  227. div.hide(3000);
  228. }, timeout);
  229. }
  230. return div;
  231. }
  232.  
  233.  
  234. function filterUniversalUrl(url) {
  235. try {
  236. url = url.match(/http.+/)[0];
  237. } catch(e) { }
  238. try {
  239. url = url.replace(/https?:\/\/(www.)?/,"");
  240. } catch(e) { }
  241. if(url.startsWith("imdb.com/") && url.match(/(imdb\.com\/\w+\/\w+\/)/)) {
  242. // Remove movie subpage from imdb url
  243. return url.match(/(imdb\.com\/\w+\/\w+\/)/)[1];
  244. } else if(url.startsWith("thetvdb.com/")) {
  245. // Do nothing with thetvdb.com urls
  246. return url;
  247. } else if(url.startsWith("boxofficemojo.com/")) {
  248. // Keep the important id= on
  249. try {
  250. var parts = url.split("?");
  251. var page = url[0] + "?";
  252. var idparam = url[1].match(/(id=.+?)(\.|&)/)[1];
  253. return page+idparam;
  254. } catch(e) {
  255. return url;
  256. }
  257. } else {
  258. // Default: Remove parameters
  259. return url.split("?")[0].split("&")[0];
  260. }
  261. }
  262.  
  263. function addToMap(url, metaurl) {
  264. var data = JSON.parse(GM_getValue("map","{}"));
  265. var url = filterUniversalUrl(url);
  266. var metaurl = metaurl.replace(/^http:\/\/(www.)?metacritic\.com\//,"");
  267.  
  268. data[url] = metaurl;
  269. GM_setValue("map", JSON.stringify(data));
  270. (new Image()).src = baseURL_whitelist + "?docurl="+encodeURIComponent(url)+"&metaurl="+encodeURIComponent(metaurl)+"&ref="+encodeURIComponent(randomStringId());
  271. return [url, metaurl];
  272. }
  273.  
  274. function addToBlacklist(url, metaurl) {
  275. var data = JSON.parse(GM_getValue("black","[]"));
  276. var url = filterUniversalUrl(url);
  277. var metaurl = metaurl.replace(/^http:\/\/(www.)?metacritic\.com\//,"");
  278.  
  279. data.push([url,metaurl]);
  280. GM_setValue("black", JSON.stringify(data));
  281. (new Image()).src = baseURL_blacklist + "?docurl="+encodeURIComponent(url)+"&metaurl="+encodeURIComponent(metaurl)+"&ref="+encodeURIComponent(randomStringId());
  282. return [url, metaurl];
  283. }
  284.  
  285.  
  286.  
  287.  
  288. function isBlacklistedUrl(docurl, metaurl) {
  289.  
  290. docurl = filterUniversalUrl(docurl);
  291. docurl = docurl.replace(/https?:\/\/(www.)?/,"");
  292. metaurl = metaurl.replace(/^http:\/\/(www.)?metacritic\.com\//,"");
  293. metaurl = metaurl.replace(/\/\//g,"/").replace(/\/\//g,"/");; // remove double slash
  294. metaurl = metaurl.replace(/^\/+/,""); // remove starting slash
  295. var data = JSON.parse(GM_getValue("black","[]")); // [ [docurl0, metaurl0] , [docurl1, metaurl1] , ... ]
  296. for(var i = 0; i < data.length; i++) {
  297. if(data[i][0] == docurl && data[i][1] == metaurl) {
  298. return true;
  299. }
  300. }
  301. return false;
  302. }
  303.  
  304. function isBlacklisted(metaurl) {
  305. return isBlacklistedUrl("" + document.location.host.replace(/^www\./,"") + document.location.pathname + document.location.search, metaurl);
  306. }
  307.  
  308.  
  309.  
  310. function listenForHotkeys(code, cb) {
  311. // Call cb() as soon as the code sequence was typed
  312. var i = 0;
  313. $(document).bind("keydown.listenForHotkeys",function(ev) {
  314. if(document.activeElement == document.body) {
  315. if(ev.key != code[i]) {
  316. i = 0;
  317. } else {
  318. i++;
  319. if(i == code.length) {
  320. ev.preventDefault();
  321. $(document).unbind("keydown.listenForHotkeys");
  322. cb();
  323. }
  324. }
  325. }
  326. });
  327. }
  328.  
  329.  
  330. function metacritic_hoverInfo(url, docurl, cb, errorcb) {
  331. // Get the metacritic hover info. Requests are cached.
  332. var handleresponse = function(response, cached) {
  333. if(response.status == 200 && response.responseText && cb) {
  334. if(~response.responseText.indexOf('"jsonRedirect"')) { // {"viewer":{},"mixpanelToken":"6e219fd....","mixpanelDistinctId":"255.255.255.255","omnitureDebug":0,"jsonRedirect":"\/movie\/national-lampoons-vacation"}
  335. var blacklistedredirect = false;
  336. var j = JSON.parse(response.responseText);
  337. current.url = baseURL + j["jsonRedirect"];
  338. delete cache[url]; // Delete original url from cache. The redirect URL will then be saved in metacritic_hoverInfo(...)
  339.  
  340. // Blacklist items from database received?
  341. if("blacklist" in j && j.blacklist && j.blacklist.length) {
  342. // Save new blacklist items
  343. var data = JSON.parse(GM_getValue("black","[]"));
  344. for(var i = 0; i < j.blacklist.length; i++) {
  345. var save_docurl = j.blacklist[i].docurl;
  346. var save_metaurl = j.blacklist[i].metaurl;
  347. data.push([save_docurl,save_metaurl]);
  348. if(j["jsonRedirect"] == "/"+save_metaurl) {
  349. // Redirect is blacklisted!
  350. blacklistedredirect = true;
  351. }
  352. }
  353. GM_setValue("black", JSON.stringify(data));
  354. }
  355. if(blacklistedredirect && errorcb) {
  356. // Redirect was blacklisted, show nothing
  357. errorcb(response.responseText, new Date(response.time));
  358. } else {
  359. // Load redirect
  360. metacritic_hoverInfo(baseURL + j["jsonRedirect"], false, cb, errorcb);
  361. }
  362. } else {
  363. cb(response.responseText, new Date(response.time));
  364. }
  365. } else if(response.status != 200 && errorcb) {
  366. errorcb(response.responseText, new Date(response.time));
  367. if(!cached)
  368. console.log("Show metacritic ratings: Error:"+response.status+"\n"+url);
  369. } else if(!response.responseText) {
  370. errorcb("", new Date(response.time));
  371. if(!cached)
  372. console.log("Show metacritic ratings: Error: response empty. Status:"+response.status+"\n"+url);
  373. }
  374. };
  375. var cache = JSON.parse(GM_getValue("hovercache","{}"));
  376. for(var prop in cache) {
  377. // Delete cached values, that are older than 2 hours
  378. if((new Date()).getTime() - (new Date(cache[prop].time)).getTime() > 2*60*60*1000) {
  379. delete cache[prop];
  380. }
  381. }
  382. if(url in cache) {
  383. handleresponse(cache[url], true);
  384. } else {
  385. var requestURL = url;
  386. var requestParams = "hoverinfo=1";
  387. if(docurl && docurl.indexOf("metacritic.com") == -1 && docurl.indexOf(baseURL_database) == -1) {
  388. // Ask database for correct metacritic entry:
  389. requestURL = baseURL_database;
  390. requestParams = "m=" + encodeURIComponent(docurl) + "&a=" + encodeURIComponent(url);
  391. }
  392. GM_xmlhttpRequest({
  393. method: "POST",
  394. url: requestURL,
  395. data: requestParams,
  396. headers: {
  397. "Referer" : url,
  398. "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8",
  399. "Host" : getHostname(requestURL), // This is important, otherwise Metacritic refuses to answer!
  400. "User-Agent" : "MetacriticUserscript "+navigator.userAgent,
  401. "X-Requested-With" : "XMLHttpRequest"
  402. },
  403. onload: function(response) {
  404. response.time = (new Date()).toJSON();
  405. cache[url] = response;
  406. GM_setValue("hovercache",JSON.stringify(cache));
  407. handleresponse(response, false);
  408. },
  409. onerror: function(response) {
  410. console.log("Show metacritic ratings: Hover info error: "+response.status+"\nURL: "+requestURL+"\nResponse:\n"+response.responseText);
  411. },
  412. });
  413. }
  414. }
  415. function metacritic_searchResults(url, cb, errorcb) {
  416. // Get metacritic search results. Requests are cached.
  417. var handleresponse = function(response, cached) {
  418. if(response.results.length && cb) {
  419. cb(response.results, new Date(response.time));
  420. } else if(response.results.length == 0 && errorcb) {
  421. errorcb(response.results, new Date(response.time));
  422. }
  423. };
  424. var cache = JSON.parse(GM_getValue("searchcache","{}"));
  425. for(var prop in cache) {
  426. // Delete cached values, that are older than 2 hours
  427. if((new Date()).getTime() - (new Date(cache[prop].time)).getTime() > 2*60*60*1000) {
  428. delete cache[prop];
  429. }
  430. }
  431. if(url in cache) {
  432. handleresponse(cache[url], true);
  433. } else {
  434. GM_xmlhttpRequest({
  435. method: "GET",
  436. url: url,
  437. headers: {
  438. "Referer" : url,
  439. "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8",
  440. "Host" : "www.metacritic.com",
  441. "User-Agent" : "MetacriticUserscript "+navigator.userAgent,
  442. },
  443. onload: function(response) {
  444. var results = [];
  445. if(!~response.responseText.indexOf("No search results found.")) {
  446. var d = $('<html>').html(response.responseText);
  447. d.find("ul.search_results.module .result").each(function() {
  448. results.push(this.innerHTML);
  449. });
  450. }
  451.  
  452. response = {
  453. time : (new Date()).toJSON(),
  454. results : results,
  455. };
  456. cache[url] = response;
  457. GM_setValue("searchcache",JSON.stringify(cache));
  458. handleresponse(response, false);
  459. },
  460. onerror: function(response) {
  461. console.log("Show metacritic ratings: Search error: "+response.status+"\n"+url);
  462. handleresponse({
  463. time : (new Date()).toJSON(),
  464. results : [],
  465. }, false);
  466. }
  467. });
  468. }
  469. }
  470.  
  471. function metacritic_showHoverInfo(url, docurl) {
  472. if(!url) {
  473. return;
  474. }
  475. metacritic_hoverInfo(url, docurl?docurl:false,
  476. // On Success
  477. function(html, time) {
  478. $("#mcdiv123").remove();
  479. var div = $('<div id="mcdiv123"></div>').appendTo(document.body);
  480. div.css({
  481. position:"fixed",
  482. bottom :0,
  483. left: 0,
  484. minWidth: 300,
  485. backgroundColor: "#fff",
  486. border: "2px solid #bbb",
  487. borderRadius:" 6px",
  488. boxShadow: "0 0 3px 3px rgba(100, 100, 100, 0.2)",
  489. color: "#000",
  490. padding:" 3px",
  491. zIndex: "5010001",
  492. });
  493. // Functions for communication between page and iframe
  494. // Mozilla can access parent.document
  495. // Chrome can use postMessage()
  496. var frame_status = false; // if this remains false, loading the frame content failed. A reason could be "Content Security Policy"
  497. function loadExternalImage(url, myframe) {
  498. // Load external image, bypass CSP
  499. GM_xmlhttpRequest({
  500. method: "GET",
  501. url: url,
  502. responseType : "arraybuffer",
  503. onload: function(response) {
  504. myframe.contentWindow.postMessage({
  505. "mcimessage_imgLoaded" : true,
  506. "mcimessage_imgData" : response.response,
  507. "mcimessage_imgOrgSrc" : url
  508. },'*');
  509. }
  510. });
  511. }
  512. var functions = {
  513. "other" : {
  514. "parent": function() {
  515. var f = parent.document.getElementById('mciframe123');
  516. window.addEventListener("message", function(e){
  517. if(typeof e.data != "object") {
  518. return;
  519. } else if("mcimessage0" in e.data) {
  520. frame_status = true; // Frame content was loaded successfully
  521. } else if("mcimessage_loadImg" in e.data) {
  522. loadExternalImage(e.data.mcimessage_imgUrl, f);
  523. }
  524. });
  525. },
  526. "frame" : function sizecorrection() {
  527. parent.postMessage({"mcimessage0":true},'*'); // Loading frame content was successfull
  528. window.addEventListener("message", function(e){
  529. if(typeof e.data == "object" && "mcimessage_imgLoaded" in e.data) {
  530. // Load external image
  531. var arrayBufferView = new Uint8Array( e.data["mcimessage_imgData"] );
  532. var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
  533. var urlCreator = window.URL || window.webkitURL;
  534. var imageUrl = urlCreator.createObjectURL( blob );
  535. var img = failedImages[e.data["mcimessage_imgOrgSrc"]];
  536. img.src = imageUrl;
  537. }
  538. });
  539. var f = parent.document.getElementById('mciframe123');
  540. for(var i =0; f.clientHeight < document.body.scrollHeight && i < 100; i++) {
  541. f.style.width = parseInt(f.style.width)+10+"px";
  542. }
  543. if(f.clientHeight < document.body.scrollHeight) {
  544. f.style.height = parseInt(f.style.height)+15+"px";
  545. f.style.width = "300px";
  546. if(parseInt(f.style.height) > 500) {
  547. return;
  548. }
  549. sizecorrection();
  550. }
  551. }
  552. },
  553. "chrome" : {
  554. "parent" : function() {
  555. var f = parent.document.getElementById('mciframe123');
  556. window.addEventListener("message", function(e){
  557. if(typeof e.data != "object") {
  558. return;
  559. } else if("mcimessage0" in e.data) {
  560. frame_status = true; // Frame content was loaded successfully
  561. } else if("mcimessage1" in e.data) {
  562. f.style.width = parseInt(f.style.width)+10+"px";
  563. } else if("mcimessage2" in e.data) {
  564. f.style.height = parseInt(f.style.height)+15+"px";
  565. f.style.width = "300px";
  566. } else if("mcimessage_loadImg" in e.data) {
  567. loadExternalImage(e.data.mcimessage_imgUrl, f);
  568. } else {
  569. return;
  570. }
  571. f.contentWindow.postMessage({
  572. "mcimessage3" : true,
  573. "mciframe123_clientHeight" : f.clientHeight,
  574. "mciframe123_clientWidth" : f.clientWidth,
  575. },'*');
  576. });
  577. },
  578. "frame" : function() {
  579. parent.postMessage({"mcimessage0":true},'*'); // Loading frame content was successfull
  580. var i = 0;
  581. window.addEventListener("message", function(e){
  582. if(typeof e.data == "object" && "mcimessage_imgLoaded" in e.data) {
  583. // Load external image
  584. var arrayBufferView = new Uint8Array( e.data["mcimessage_imgData"] );
  585. var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
  586. var urlCreator = window.URL || window.webkitURL;
  587. var imageUrl = urlCreator.createObjectURL( blob );
  588. var img = failedImages[e.data["mcimessage_imgOrgSrc"]];
  589. img.src = imageUrl;
  590. }
  591. if(!("mcimessage3" in e.data)) return;
  592. if(e.data.mciframe123_clientHeight < document.body.scrollHeight && i < 100) {
  593. parent.postMessage({"mcimessage1":1},'*');
  594. i++;
  595. }
  596. if(i >= 100) {
  597. parent.postMessage({"mcimessage2":1},'*')
  598. i = 0;
  599. }
  600. });
  601. parent.postMessage({"mcimessage1":1},'*');
  602. }
  603. }
  604. };
  605.  
  606. var css = "#hover_div .clr { clear: both}#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}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;}.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;}.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.user { border-radius: 55%; color: #fff;}.metascore_anchor, 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;}";
  607.  
  608. var framesrc = 'data:text/html,';
  609. framesrc += encodeURIComponent('<!DOCTYPE html>\
  610. <html lang="en">\
  611. <head>\
  612. <meta charset="utf-8">\
  613. <title>Metacritic info</title>\
  614. <style>body { margin:0px; padding:0px; background:white; }' + css
  615. +'\
  616. </style>\
  617. <script>\
  618. var failedImages = {};\
  619. function detectCSP(img) {\
  620. if(img.complete && (!img.naturalWidth || !img.naturalHeight)) {\
  621. return true;\
  622. }\
  623. return false;\
  624. }\
  625. function findCSPerrors() {\
  626. var imgs = document.querySelectorAll("img");\
  627. for(var i = 0; i < imgs.length; i++) {\
  628. if(imgs[i].complete && detectCSP(imgs[i])) {\
  629. fixCSP(imgs[i]);\
  630. }\
  631. }\
  632. }\
  633. function fixCSP(img) {\
  634. console.log("Loading image failed. Bypassing CSP...");\
  635. failedImages[img.src] = img;\
  636. parent.postMessage({"mcimessage_loadImg":true, "mcimessage_imgUrl": img.src},"*"); \
  637. }\
  638. function on_load() {\
  639. ('+functions[mybrowser].frame.toString()+')();\
  640. window.setTimeout(findCSPerrors, 500);\
  641. \
  642. }\
  643. </script>\
  644. </head>\
  645. <body onload="on_load();">\
  646. <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">\
  647. <div class="hover_content">'+fixMetacriticURLs(html)+'</div>\
  648. </div>\
  649. </body>\
  650. </html>');
  651. var frame = $("<iframe></iframe>").appendTo(div);
  652. frame.attr("id","mciframe123");
  653. frame.attr("src",framesrc);
  654. frame.attr("scrolling","auto");
  655. frame.css({
  656. width: 300,
  657. height: 170,
  658. border: "none"
  659. });
  660. window.setTimeout(function() {
  661. if(!frame_status) { // Loading frame content failed.
  662. // Directly inject the html without an iframe (this may break the site or the metacritic)
  663. console.log("Loading iframe content failed. Injecting directly.");
  664. $("head").append("<style>"+css+"</style>");
  665. 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">\
  666. <div class="hover_content">'+fixMetacriticURLs(html)+'</div>\
  667. </div>');
  668. frame.replaceWith(noframe);
  669. }
  670. },2000);
  671. functions[mybrowser].parent();
  672. var sub = $("<div></div>").appendTo(div);
  673. $('<time style="color:#b6b6b6; font-size: 11px;" datetime="'+time+'" title="'+time.toLocaleTimeString()+" "+time.toLocaleDateString()+'">'+minutesSince(time)+'</time>').appendTo(sub);
  674. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="'+url+'" title="Open Metacritic">'+decodeURI(url.replace("http://www.","@"))+'</a>').appendTo(sub);
  675. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px; padding-left:5px;">&#10062;</span>').appendTo(sub).click(function() {
  676. document.body.removeChild(this.parentNode.parentNode);
  677. });
  678. $('<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() {
  679. var docurl = document.location.href;
  680. var metaurl = $(this).data("url");
  681. var r = addToMap(docurl,metaurl);
  682. balloonAlert("Thanks for your submission!\n\nSaved as a correct entry.\n\n"+r[0]+"\n"+r[1], 6000, "Success");
  683. });
  684. $('<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() {
  685. if(!confirm("This is NOT the correct entry!\n\nAdd to blacklist?")) return;
  686. var docurl = document.location.href;
  687. var metaurl = $(this).data("url");
  688. var r = addToBlacklist(docurl,metaurl);
  689. balloonAlert("Thanks for your submission!\n\nSaved to blacklist.\n\n"+r[0]+"\n"+r[1], 6000, "Success");
  690. // Open search
  691. metacritic_searchcontainer(null, current.searchTerm);
  692. metacritic_search(null, current.searchTerm);
  693. });
  694.  
  695. },
  696. // On error i.e. no result on metacritic.com
  697. function(html, time) {
  698. // Make search available
  699. metacritic_waitForHotkeys();
  700. var handleresponse = function(response) {
  701. var data;
  702. var multiple = false;
  703. try {
  704. data = JSON.parse(response.responseText);
  705. } catch(e) {
  706. console.log("Error in JSON: search_term="+current.searchTerm);
  707. console.log(e);
  708. }
  709. if(data && data.autoComplete && data.autoComplete.results && data.autoComplete.results.length) {
  710. // Remove data with wrong type
  711. data.autoComplete = data.autoComplete.results;
  712. var newdata = [];
  713. data.autoComplete.forEach(function(result) {
  714. if(metacritic2searchType(result.refType) == current.type) {
  715. newdata.push(result);
  716. }
  717. });
  718. data.autoComplete = newdata;
  719. if(data.autoComplete.length == 0) {
  720. // No results
  721. console.log("No results (after filtering by type) for search_term="+current.searchTerm);
  722. } else if(data.autoComplete.length == 1) {
  723. // One result, let's show it
  724. if(!isBlacklisted(baseURL + data.autoComplete[0].url)) {
  725. metacritic_showHoverInfo(baseURL + data.autoComplete[0].url);
  726. return;
  727. }
  728. } else {
  729. // More than one result
  730. multiple = true;
  731. console.log("Multiple results for search_term="+current.searchTerm);
  732. var exactMatches = [];
  733. data.autoComplete.forEach(function(result,i) { // Try to find the correct result by matching the search term to exactly one movie title
  734. if(current.searchTerm == result.name) {
  735. exactMatches.push(result);
  736. }
  737. });
  738. if(exactMatches.length == 1) {
  739. // Only one exact match, let's show it
  740. console.log("Only one exact match for search_term="+current.searchTerm);
  741. if(!isBlacklisted(baseURL + exactMatches[0].url)) {
  742. metacritic_showHoverInfo(baseURL + exactMatches[0].url);
  743. return;
  744. }
  745. }
  746. }
  747. } else {
  748. console.log("No results (at all) for search_term="+current.searchTerm);
  749. }
  750. // HERE: multiple results or no result. The user may type "meta" now
  751. if(multiple) {
  752. balloonAlert("Multiple metacritic results. Type &#34;meta&#34; for manual search.", 10000, false, {bottom: 5, top:"auto", maxWidth: 400, paddingRight: 5}, metacritic_searchcontainer);
  753. }
  754. };
  755. var cache = JSON.parse(GM_getValue("autosearchcache","{}"));
  756. for(var prop in cache) {
  757. // Delete cached values, that are older than 2 hours
  758. if((new Date()).getTime() - (new Date(cache[prop].time)).getTime() > 2*60*60*1000) {
  759. delete cache[prop];
  760. }
  761. }
  762. if(current.type == "music") {
  763. current.searchTerm = current.data[0];
  764. } else {
  765. current.searchTerm = current.data.join(" ");
  766. }
  767. if(current.searchTerm in cache) {
  768. handleresponse(cache[current.searchTerm], true);
  769. } else {
  770. GM_xmlhttpRequest({
  771. method: "POST",
  772. url: baseURL_autosearch,
  773. data: "search_term="+encodeURIComponent(current.searchTerm)+"&image_size=98&search_each=1&sort_type=popular",
  774. headers: {
  775. "Referer" : url,
  776. "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8",
  777. "Host" : "www.metacritic.com",
  778. "User-Agent" : "MetacriticUserscript Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0",
  779. "X-Requested-With" : "XMLHttpRequest"
  780. },
  781. onload: function(response) {
  782. response = {
  783. time : (new Date()).toJSON(),
  784. responseText : response.responseText,
  785. };
  786. cache[current.searchTerm] = response;
  787. GM_setValue("autosearchcache",JSON.stringify(cache));
  788. handleresponse(response, false);
  789. }
  790. });
  791. }
  792. });
  793. }
  794.  
  795. function metacritic_waitForHotkeys() {
  796. listenForHotkeys("meta",metacritic_searchcontainer);
  797. }
  798.  
  799. function metacritic_searchcontainer(ev, query) {
  800. if(!query) {
  801. if(current.type == "music") {
  802. query = current.data[0];
  803. } else {
  804. query = current.data.join(" ");
  805. }
  806. }
  807. $("#mcdiv123").remove();
  808. var div = $('<div id="mcdiv123"></div>').appendTo(document.body);
  809. div.css({
  810. position:"fixed",
  811. bottom :0,
  812. left: 0,
  813. minWidth: 300,
  814. maxHeight: "80%",
  815. maxWidth: 640,
  816. overflow:"auto",
  817. backgroundColor: "#fff",
  818. border: "2px solid #bbb",
  819. borderRadius:" 6px",
  820. boxShadow: "0 0 3px 3px rgba(100, 100, 100, 0.2)",
  821. color: "#000",
  822. padding:" 3px",
  823. zIndex: "5010001",
  824. });
  825. var query = $('<input type="text" size="60" id="mcisearchquery">').appendTo(div).focus().val(query).on('keypress', function(e) {
  826. var code = e.keyCode || e.which;
  827. if(code == 13) { // Enter key
  828. metacritic_search.call(this,e);
  829. }
  830. });
  831. $('<button id="mcisearchbutton">').text("Search").appendTo(div).click(metacritic_search);
  832. }
  833.  
  834.  
  835. function metacritic_search(ev, query) {
  836. if(!query) { // Use values from search form
  837. query = $("#mcisearchquery").val();
  838. }
  839. var type = searchType2metacritic(current.type);
  840.  
  841. var style = document.createElement('style');
  842. style.type = 'text/css';
  843. style.innerHTML = CSS;
  844. document.head.appendChild(style);
  845.  
  846. var div = $("#mcdiv123");
  847. var loader = $('<div style="width:20px; height:20px;" class="grespinner"></div>').appendTo($("#mcisearchbutton"));
  848. var url = baseURL_search.replace("{type}",encodeURIComponent(type)).replace("{query}",encodeURIComponent(query));
  849.  
  850. metacritic_searchResults(url,
  851. // On success
  852. function(results, time) {
  853. loader.remove();
  854. var accept = function(ev) {
  855. var a = $(this.parentNode).find("a[href*='metacritic.com']");
  856. var metaurl = a.attr("href");
  857. var docurl = document.location.href;
  858.  
  859. addToMap(docurl,metaurl);
  860. metacritic_showHoverInfo(metaurl);
  861. };
  862. var denyAll = function(ev) {
  863. var urls = [];
  864. var docurl = document.location.href;
  865. $("#mcdiv123searchresults").find("div.result a[href*='metacritic.com']").each(function() {
  866. addToBlacklist(docurl, this.href);
  867. });
  868. };
  869. var resultdiv = $("#mcdiv123searchresults").length?$("#mcdiv123searchresults").html(""):$('<div id="mcdiv123searchresults"></div>').css("max-width","95%").appendTo(div);
  870. results.forEach(function(html) {
  871. var singleresult = $('<div class="result"></div>').html(fixMetacriticURLs(html)+'<div style="clear:left"></div>').appendTo(resultdiv);
  872. $('<span title="Assist us: This is the correct entry!" style="cursor:pointer; color:green; font-size: 13px;">&check;</span>').prependTo(singleresult).click(accept);
  873. });
  874. var sub = $("<div></div>").appendTo(div);
  875. $('<time style="color:#b6b6b6; font-size: 11px;" datetime="'+time+'" title="'+time.toLocaleFormat()+'">'+minutesSince(time)+'</time>').appendTo(sub);
  876. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="'+url+'" title="Open Metacritic">'+decodeURI(url.replace("http://www.","@"))+'</a>').appendTo(sub);
  877. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px;">&#10062;</span>').appendTo(sub).click(function() {
  878. document.body.removeChild(this.parentNode.parentNode);
  879. });
  880. $('<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()});
  881. },
  882. // On error i.e. no results
  883. function(results, time) {
  884. loader.remove();
  885. var resultdiv = $("#mcdiv123searchresults").length?$("#mcdiv123searchresults").html(""):$('<div id="mcdiv123searchresults"></div>').appendTo(div);
  886. resultdiv.html("No search results.");
  887. var sub = $("<div></div>").appendTo(div);
  888. $('<time style="color:#b6b6b6; font-size: 11px;" datetime="'+time+'" title="'+time.toLocaleFormat()+'">'+minutesSince(time)+'</time>').appendTo(sub);
  889. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="'+url+'" title="Open Metacritic">'+decodeURI(url.replace("http://www.","@"))+'</a>').appendTo(sub);
  890. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px;">&#10062;</span>').appendTo(sub).click(function() {
  891. document.body.removeChild(this.parentNode.parentNode);
  892. });
  893. }
  894. );
  895. }
  896.  
  897. var current = {
  898. url : null,
  899. type : null,
  900. data : null, // Array of raw search keys
  901. searchTerm : null
  902. };
  903.  
  904.  
  905. function showURL(url) {
  906. if(!isBlacklisted(url)) {
  907. var docurl = document.location.host.replace(/^www\./,"") + document.location.pathname + document.location.search;
  908. docurl = filterUniversalUrl(docurl);
  909. metacritic_showHoverInfo(url, docurl);
  910. } else {
  911. console.log(url +" is blacklisted!");
  912. }
  913. }
  914.  
  915.  
  916. var metacritic = {
  917. "mapped" : function metacritic_mapped(url, type) {
  918. // url was in the map/whitelist
  919. current.data = [url]
  920. current.url = url;
  921. current.type = type;
  922. current.searchTerm = url;
  923. showURL(url);
  924. },
  925. "music" : function metacritic_music(artistname, albumname) {
  926. current.data = [albumname.trim(),artistname.trim()]
  927. artistname = name2metacritic(artistname);
  928. albumname = albumname.replace("&"," ");
  929. albumname = name2metacritic(albumname);
  930. var url = baseURL_music + albumname + "/" + artistname;
  931. current.url = url;
  932. current.type = "music";
  933. current.searchTerm = albumname + "/" + artistname;
  934. showURL(url);
  935. },
  936. "movie" : function metacritic_movie(moviename) {
  937. current.data = [moviename.trim()]
  938. moviename = name2metacritic(moviename);
  939. var url = baseURL_movie + moviename;
  940. current.url = url;
  941. current.type = "movie";
  942. current.searchTerm = moviename;
  943. showURL(url);
  944. },
  945. "tv" : function metacritic_tv(seriesname) {
  946. current.data = [seriesname.trim()]
  947. seriesname = name2metacritic(seriesname);
  948. var url = baseURL_tv + seriesname;
  949. current.url = url;
  950. current.type = "tv";
  951. current.searchTerm = seriesname;
  952. showURL(url);
  953. },
  954. "pcgame" : function metacritic_pcgame(gamename) {
  955. current.data = [gamename.trim()]
  956. gamename = name2metacritic(gamename);
  957. var url = baseURL_pcgame + gamename;
  958. current.url = url;
  959. current.type = "pcgame";
  960. current.searchTerm = gamename;
  961. showURL(url);
  962. },
  963. "ps4game" : function metacritic_ps4game(gamename) {
  964. current.data = [gamename.trim()]
  965. gamename = name2metacritic(gamename);
  966. var url = baseURL_ps4 + gamename;
  967. current.url = url;
  968. current.type = "ps4game";
  969. current.searchTerm = gamename;
  970. showURL(url);
  971. },
  972. "xonegame" : function metacritic_xonegame(gamename) {
  973. current.data = [gamename.trim()]
  974. gamename = name2metacritic(gamename);
  975. var url = baseURL_xone + gamename;
  976. current.url = url;
  977. current.type = "xonegame";
  978. current.searchTerm = gamename;
  979. showURL(url);
  980. }
  981. };
  982.  
  983.  
  984. var Always = () => true;
  985. var sites = {
  986. 'bandcamp' : {
  987. host : ["bandcamp.com"],
  988. condition : function() {
  989. return unsafeWindow.TralbumData
  990. },
  991. products : [{
  992. condition : Always,
  993. type : "music",
  994. data : () => [unsafeWindow.TralbumData.artist, unsafeWindow.TralbumData.current.title]
  995. }]
  996. },
  997. 'itunes' : {
  998. host : ["itunes.apple.com"],
  999. condition : Always,
  1000. products : [{
  1001. condition : () => ~document.location.href.indexOf("/album/") ,
  1002. type : "music",
  1003. data : () => [document.querySelector("h2.t-hero-subheadline").textContent.trim(), document.querySelector("h1.t-hero-headline").textContent.trim()]
  1004. }]
  1005. },
  1006. 'googleplay' : {
  1007. host : ["play.google.com"],
  1008. condition : Always,
  1009. products : [
  1010. {
  1011. condition : () => ~document.location.href.indexOf("/album/"),
  1012. type : "music",
  1013. data : () => [document.querySelector("*[itemprop=byArtist] a").textContent, document.querySelector("*[itemprop=name]").textContent]
  1014. },
  1015. {
  1016. condition : () => ~document.location.href.indexOf("/movies/details/"),
  1017. type : "movie",
  1018. data : () => document.querySelector("*[itemprop=name]").textContent
  1019. }
  1020. ]
  1021. },
  1022. 'imdb' : {
  1023. host : ["imdb.com"],
  1024. condition : Always,
  1025. products : [
  1026. {
  1027. condition : function() {
  1028. var e = document.querySelector("meta[property='og:type']");
  1029. if(e) {
  1030. return e.content == "video.movie"
  1031. }
  1032. return false;
  1033. },
  1034. type : "movie",
  1035. data : function() {
  1036. if(document.querySelector("h1[itemprop=name]")) { // Movie homepage (New design 2015-12)
  1037. return document.querySelector("h1[itemprop=name]").firstChild.textContent.trim();
  1038. } else if(document.querySelector("*[itemprop=name] a") && document.querySelector("*[itemprop=name] a").firstChild.data) { // Subpage of a move
  1039. return document.querySelector("*[itemprop=name] a").firstChild.data.trim();
  1040. } else if(document.querySelector(".title-extra[itemprop=name]")) { // Movie homepage: sub-/alternative-/original title
  1041. return document.querySelector(".title-extra[itemprop=name]").firstChild.textContent.replace(/\"/g,"").trim();
  1042. } else { // Movie homepage (old design)
  1043. return document.querySelector("*[itemprop=name]").firstChild.textContent.trim();
  1044. }
  1045. }
  1046. },
  1047. {
  1048. condition : function() {
  1049. var e = document.querySelector("meta[property='og:type']");
  1050. if(e) {
  1051. return e.content == "video.tv_show"
  1052. }
  1053. return false;
  1054. },
  1055. type : "tv",
  1056. data : () => document.querySelector("*[itemprop=name]").textContent
  1057. }
  1058. ]
  1059. },
  1060. 'steam' : {
  1061. host : ["store.steampowered.com"],
  1062. condition : () => document.querySelector("*[itemprop=name]"),
  1063. products : [{
  1064. condition : Always,
  1065. type : "pcgame",
  1066. data : () => document.querySelector("*[itemprop=name]").textContent
  1067. }]
  1068. },
  1069. 'tv.com' : {
  1070. host : ["www.tv.com"],
  1071. condition : () => document.querySelector("meta[property='og:type']"),
  1072. products : [{
  1073. condition : () => document.querySelector("meta[property='og:type']").content == "tv_show" && document.querySelector("h1[data-name]"),
  1074. type : "tv",
  1075. data : () => document.querySelector("h1[data-name]").dataset.name
  1076. }]
  1077. },
  1078. 'rottentomatoes' : {
  1079. host : ["www.rottentomatoes.com"],
  1080. condition : Always,
  1081. products : [{
  1082. condition : () => document.location.pathname.startsWith("/m/"),
  1083. type : "movie",
  1084. data : () => document.querySelector("h1").firstChild.textContent
  1085. },
  1086. {
  1087. condition : () => document.location.pathname.startsWith("/tv/") ,
  1088. type : "tv",
  1089. data : () => unsafeWindow.BK.TvSeriesTitle
  1090. }
  1091. ]
  1092. },
  1093. 'serienjunkies' : {
  1094. host : ["www.serienjunkies.de"],
  1095. condition : Always,
  1096. products : [{
  1097. condition : () => Always,
  1098. type : "tv",
  1099. data : function() {
  1100. if(document.querySelector("h1[itemprop=name]")) {
  1101. return document.querySelector("h1[itemprop=name]").textContent;
  1102. } else {
  1103. var n = $("a:contains(Details zur)");
  1104. if(n) {
  1105. var name = n.text().match(/Details zur Produktion der Serie (.+)/)[1];
  1106. return name;
  1107. }
  1108. }
  1109. }
  1110. }]
  1111. },
  1112. 'gamespot' : {
  1113. host : ["gamespot.com"],
  1114. condition : () => document.querySelector("[itemprop=device]"),
  1115. products : [
  1116. {
  1117. condition : () => ~$("[itemprop=device]").text().indexOf("PC"),
  1118. type : "pcgame",
  1119. data : () => document.querySelector("h1[itemprop=name]").textContent
  1120. },
  1121. {
  1122. condition : () => ~$("[itemprop=device]").text().indexOf("PS4"),
  1123. type : "ps4game",
  1124. data : () => document.querySelector("h1[itemprop=name]").textContent
  1125. },
  1126. {
  1127. condition : () => ~$("[itemprop=device]").text().indexOf("XONE"),
  1128. type : "xonegame",
  1129. data : () => document.querySelector("h1[itemprop=name]").textContent
  1130. }
  1131. ]
  1132. },
  1133. 'amazon' : {
  1134. host : ["amazon."],
  1135. condition : Always,
  1136. products : [
  1137. {
  1138. condition : function() {
  1139. try {
  1140. if(document.querySelector(".nav-categ-image").alt.toLowerCase().indexOf("musi") != -1) {
  1141. return true;
  1142. }
  1143. } catch(e) {}
  1144. var music = ["Music","Musique","Musik","Música","Musica","音楽"];
  1145. return music.some(function(s) {
  1146. if(~document.title.indexOf(s)) {
  1147. return true;
  1148. } else {
  1149. return false;
  1150. }
  1151. });
  1152. },
  1153. type : "music",
  1154. data : function() {
  1155. var artist = document.querySelector("#ProductInfoArtistLink").textContent.trim();
  1156. var title = document.querySelector("#title_feature_div").textContent.trim();
  1157. title = title.replace(/\[([^\]]*)\]/g,""); // Remove [brackets] and their content
  1158. return [artist, title];
  1159. }
  1160. },
  1161. {
  1162. condition : () => (document.getElementById("aiv-content-title") && document.getElementsByClassName("season-single-dark").length),
  1163. type : "tv",
  1164. data : () => document.getElementById("aiv-content-title").firstChild.data.trim()
  1165. },
  1166. {
  1167. condition : () => document.getElementById("aiv-content-title"),
  1168. type : "movie",
  1169. data : () => document.getElementById("aiv-content-title").firstChild.data.trim()
  1170. }
  1171. ]
  1172. },
  1173. 'BoxOfficeMojo' : {
  1174. host : ["boxofficemojo.com"],
  1175. condition : () => ~document.location.search.indexOf("id="),
  1176. products : [{
  1177. condition : () => document.querySelector("#body table:nth-child(2) tr:first-child b"),
  1178. type : "movie",
  1179. data : () => document.querySelector("#body table:nth-child(2) tr:first-child b").firstChild.data
  1180. }]
  1181. },
  1182. 'AllMovie' : {
  1183. host : ["allmovie.com"],
  1184. condition : () => document.querySelector("h2[itemprop=name].movie-title"),
  1185. products : [{
  1186. condition : () => document.querySelector("h2[itemprop=name].movie-title"),
  1187. type : "movie",
  1188. data : () => document.querySelector("h2[itemprop=name].movie-title").firstChild.data.trim()
  1189. }]
  1190. },
  1191. 'en.wikipedia' : {
  1192. host : ["en.wikipedia.org"],
  1193. condition : Always,
  1194. products : [{
  1195. condition : function() {
  1196. if(!document.querySelector(".infobox .summary")) {
  1197. return false;
  1198. }
  1199. var r = /\d\d\d\d films/;
  1200. return $("#catlinks a").filter((i,e) => e.firstChild.data.match(r)).length;
  1201. },
  1202. type : "movie",
  1203. data : () => document.querySelector(".infobox .summary").firstChild.data
  1204. },
  1205. {
  1206. condition : function() {
  1207. if(!document.querySelector(".infobox .summary")) {
  1208. return false;
  1209. }
  1210. var r = /television series/;
  1211. return $("#catlinks a").filter((i,e) => e.firstChild.data.match(r)).length;
  1212. },
  1213. type : "tv",
  1214. data : () => document.querySelector(".infobox .summary").firstChild.data
  1215. }]
  1216. },
  1217. 'movies.com' : {
  1218. host : ["movies.com"],
  1219. condition : () => document.querySelector("meta[property='og:title']"),
  1220. products : [{
  1221. condition : Always,
  1222. type : "movie",
  1223. data : () => document.querySelector("meta[property='og:title']").content
  1224. }]
  1225. },
  1226. 'themoviedb' : {
  1227. host : ["themoviedb.org"],
  1228. condition : () => document.querySelector("meta[property='og:type']"),
  1229. products : [{
  1230. condition : () => document.querySelector("meta[property='og:type']").content == "movie",
  1231. type : "movie",
  1232. data : () => document.querySelector("meta[property='og:title']").content
  1233. },
  1234. {
  1235. condition : () => document.querySelector("meta[property='og:type']").content == "tv_series",
  1236. type : "tv",
  1237. data : () => document.querySelector("meta[property='og:title']").content
  1238. }]
  1239. },
  1240. 'letterboxd' : {
  1241. host : ["letterboxd.com"],
  1242. condition : () => unsafeWindow.filmData && "name" in unsafeWindow.filmData,
  1243. products : [{
  1244. condition : Always,
  1245. type : "movie",
  1246. data : () => unsafeWindow.filmData.name
  1247. }]
  1248. },
  1249. 'TVmaze' : {
  1250. host : ["tvmaze.com"],
  1251. condition : () => document.querySelector("h1"),
  1252. products : [{
  1253. condition : Always,
  1254. type : "tv",
  1255. data : () => document.querySelector("h1").firstChild.data
  1256. }]
  1257. },
  1258. 'TVGuide' : {
  1259. host : ["tvguide.com"],
  1260. condition : Always,
  1261. products : [{
  1262. condition : () => document.location.pathname.startsWith("/tvshows/"),
  1263. type : "tv",
  1264. data : () => document.querySelector("meta[property='og:title']").content
  1265. }]
  1266. },
  1267. 'followshows' : {
  1268. host : ["followshows.com"],
  1269. condition : Always,
  1270. products : [{
  1271. condition : () => document.querySelector("meta[property='og:type']").content == "video.tv_show",
  1272. type : "tv",
  1273. data : () => document.querySelector("meta[property='og:title']").content
  1274. }]
  1275. },
  1276. 'TheTVDB' : {
  1277. host : ["thetvdb.com"],
  1278. condition : Always,
  1279. products : [{
  1280. condition : () => ~document.location.search.indexOf("tab=series"),
  1281. type : "tv",
  1282. data : () => document.querySelector("#content h1").firstChild.data
  1283. }]
  1284. },
  1285. 'ConsequenceOfSound' : {
  1286. host : ["consequenceofsound.net"],
  1287. condition : () => document.querySelector("meta[property='og:title']"),
  1288. products : [{
  1289. condition : () => document.querySelector("meta[property='og:title']").content.match(/.+: (.+) [-–] (.+)/),
  1290. type : "music",
  1291. data : function() {
  1292. var m = document.querySelector("meta[property='og:title']").content.match(/.+: (.+) [-–] (.+)/);
  1293. m.shift();
  1294. return m;
  1295. }
  1296. }]
  1297. },
  1298. 'Pitchfork' : {
  1299. host : ["pitchfork.com"],
  1300. condition : () => ~document.location.href.indexOf("/reviews/albums/"),
  1301. products : [{
  1302. condition : () => document.querySelector(".single-album-tombstone"),
  1303. type : "music",
  1304. data : function() {
  1305. var artist = document.querySelector(".single-album-tombstone .artists").innerText.trim();
  1306. var album = document.querySelector(".single-album-tombstone h1.review-title").innerText.trim();
  1307. return [artist, album];
  1308. }
  1309. }]
  1310. },
  1311. 'Last.fm' : {
  1312. host : ["last.fm"],
  1313. condition : () => document.querySelector("*[data-page-resource-type]") && document.querySelector("*[data-page-resource-type]").dataset.pageResourceType == "album",
  1314. products : [{
  1315. condition : () => document.querySelector("*[data-page-resource-type]").dataset.pageResourceName,
  1316. type : "music",
  1317. data : function() {
  1318. var artist = document.querySelector("*[data-page-resource-type]").dataset.pageResourceArtistName;
  1319. var album = document.querySelector("*[data-page-resource-type]").dataset.pageResourceName;
  1320. return [artist, album];
  1321. }
  1322. }]
  1323. },
  1324. 'TVNfo' : {
  1325. host : ["tvnfo.com"],
  1326. condition : () => document.querySelector("#tvsign"),
  1327. products : [{
  1328. condition : Always,
  1329. type : "tv",
  1330. data : () => document.querySelector(".heading h1").textContent.trim()
  1331. }]
  1332. },
  1333. 'rateyourmusic' : {
  1334. host : ["rateyourmusic.com"],
  1335. condition : () => document.querySelector("meta[property='og:type']"),
  1336. products : [{
  1337. condition : () => document.querySelector("meta[property='og:type']").content == "music.album",
  1338. type : "music",
  1339. data : function() {
  1340. var artist = document.querySelector(".section_main_info .artist").innerText.trim();
  1341. var album = document.querySelector(".section_main_info .album_title").innerText.trim();
  1342. return [artist, album];
  1343. }
  1344. }]
  1345. },
  1346. 'spotify_webplayer' : {
  1347. host : ["open.spotify.com"],
  1348. condition : () => Always,
  1349. products : [{
  1350. condition : () => document.querySelector("#main .main-view-container .content.album"),
  1351. type : "music",
  1352. data : function() {
  1353. var artist = document.querySelector("#main .media-bd div a[href*='artist']").textContent;
  1354. var album = document.querySelector("#main .media-bd h2").textContent;
  1355. return [artist, album];
  1356. }
  1357. },
  1358. {
  1359. condition : () => document.location.pathname.startsWith("/album/") && document.querySelector("meta[property='og:type']").content == "music.album",
  1360. type : "music",
  1361. data : function() {
  1362. var artist = "";
  1363. var album = document.querySelector("meta[property='og:title']").content;
  1364. return [artist, album];
  1365. }
  1366. }]
  1367. },
  1368. 'spotify' : {
  1369. host : ["play.spotify.com"],
  1370. condition : () => Always,
  1371. products : [{
  1372. condition : () => document.location.pathname.startsWith("/album/"),
  1373. type : "music",
  1374. data : function() {
  1375. var artist = document.querySelector(".context_landing p.secondary-title").textContent;
  1376. var album = document.querySelector(".context_landing p.primary-title").textContent;
  1377. return [artist, album];
  1378. }
  1379. }]
  1380. },
  1381. };
  1382.  
  1383.  
  1384. function main() {
  1385.  
  1386. var map = false;
  1387.  
  1388. for(var name in sites) {
  1389. var site = sites[name];
  1390. if(site.host.some(function(e) {return ~this.indexOf(e)}, document.location.hostname))
  1391. if(site.host.some(function(e) {return ~this.indexOf(e)}, document.location.hostname) && site.condition()) {
  1392. for(var i = 0; i < site.products.length; i++) {
  1393. if(site.products[i].condition()) {
  1394. // Check map for a match
  1395. if(map === false) {
  1396. map = JSON.parse(GM_getValue("map","{}"));
  1397. }
  1398. var docurl = document.location.host.replace(/^www\./,"") + document.location.pathname + document.location.search;
  1399. docurl = filterUniversalUrl(docurl);
  1400. if(docurl in map) {
  1401. // Found in map, show result
  1402. var metaurl = map[docurl];
  1403. metacritic["mapped"].apply(undefined, [baseURL + metaurl, site.products[i].type]);
  1404. break;
  1405. }
  1406. // Try to retrieve item name from page
  1407. var data;
  1408. try {
  1409. data = site.products[i].data();
  1410. } catch(e) {
  1411. data = false;
  1412. console.log(e);
  1413. }
  1414. if(data) {
  1415. metacritic[site.products[i].type].apply(undefined, Array.isArray(data)?data:[data]);
  1416. }
  1417. break;
  1418. }
  1419. }
  1420. break;
  1421. }
  1422. }
  1423. }
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429. main();
  1430. var lastLoc = document.location.href;
  1431. var lastContent = document.body.innerText;
  1432. var lastCounter = 0;
  1433. function newpage() {
  1434. if(lastContent == document.body.innerText && lastCounter < 15) {
  1435. window.setTimeout(newpage, 500);
  1436. lastCounter++;
  1437. } else {
  1438. lastCounter = 0;
  1439. main();
  1440. }
  1441. }
  1442. window.setInterval(function() {
  1443. if(document.location.href != lastLoc) {
  1444. lastLoc = document.location.href;
  1445. $("#mcdiv123").remove();
  1446. window.setTimeout(newpage,1000);
  1447. }
  1448. },500);
  1449.