Show Metacritic.com ratings

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

当前为 2016-01-03 提交的版本,查看 最新版本

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