Show Metacritic.com ratings (Safari)

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

Ajankohdalta 29.4.2016. Katso uusin versio.

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