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

目前为 2015-12-26 提交的版本。查看 最新版本

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