Greasy Fork 还支持 简体中文。

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-09-16 提交的版本,檢視 最新版本

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