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, TVRage.com

当前为 2016-11-29 提交的版本,查看 最新版本

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