Greasy Fork 还支持 简体中文。

Show Metacritic.com ratings

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

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