Show Metacritic.com ratings

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

当前为 2016-09-16 提交的版本,查看 最新版本

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