Greasy Fork 支持 简体中文。

Show Metacritic.com ratings

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

目前為 2018-11-20 提交的版本,檢視 最新版本

  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, TVnfo, rateyourmusic.com
  4. // @namespace cuzi
  5. // @grant GM_xmlhttpRequest
  6. // @grant GM_setValue
  7. // @grant GM_getValue
  8. // @grant unsafeWindow
  9. // @grant GM.xmlHttpRequest
  10. // @grant GM.setValue
  11. // @grant GM.getValue
  12. // @require http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
  13. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
  14. // @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
  15. // @version 40
  16. // @connect metacritic.com
  17. // @connect php-cuzi.herokuapp.com
  18. // @include https://*.bandcamp.com/*
  19. // @include https://itunes.apple.com/*/album/*
  20. // @include https://play.google.com/store/music/album/*
  21. // @include https://play.google.com/store/movies/details/*
  22. // @include https://music.amazon.com/*
  23. // @include http://www.amazon.com/*
  24. // @include https://www.amazon.com/*
  25. // @include http://www.amazon.co.uk/*
  26. // @include https://www.amazon.co.uk/*
  27. // @include http://www.amazon.fr/*
  28. // @include https://www.amazon.fr/*
  29. // @include http://www.amazon.de/*
  30. // @include https://www.amazon.de/*
  31. // @include http://www.amazon.es/*
  32. // @include https://www.amazon.es/*
  33. // @include http://www.amazon.ca/*
  34. // @include https://www.amazon.ca/*
  35. // @include http://www.amazon.in/*
  36. // @include https://www.amazon.in/*
  37. // @include http://www.amazon.it/*
  38. // @include https://www.amazon.it/*
  39. // @include http://www.amazon.co.jp/*
  40. // @include https://www.amazon.co.jp/*
  41. // @include http://www.amazon.com.mx/*
  42. // @include https://www.amazon.com.mx/*
  43. // @include http://www.amazon.com.au/*
  44. // @include https://www.amazon.com.au/*
  45. // @include http://www.imdb.com/title/*
  46. // @include https://www.imdb.com/title/*
  47. // @include http://store.steampowered.com/app/*
  48. // @include https://store.steampowered.com/app/*
  49. // @include http://www.gamespot.com/*
  50. // @include https://www.gamespot.com/*
  51. // @include http://www.serienjunkies.de/*
  52. // @include https://www.serienjunkies.de/*
  53. // @include http://www.tv.com/shows/*
  54. // @include http://www.rottentomatoes.com/m/*
  55. // @include https://www.rottentomatoes.com/m/*
  56. // @include http://www.rottentomatoes.com/tv/*
  57. // @include https://www.rottentomatoes.com/tv/*
  58. // @include http://www.rottentomatoes.com/tv/*/s*/
  59. // @include https://www.rottentomatoes.com/tv/*/s*/
  60. // @include http://www.boxofficemojo.com/movies/*
  61. // @include https://www.boxofficemojo.com/movies/*
  62. // @include http://www.allmovie.com/movie/*
  63. // @include https://www.allmovie.com/movie/*
  64. // @include https://en.wikipedia.org/*
  65. // @include http://www.movies.com/*/m*
  66. // @include https://www.themoviedb.org/movie/*
  67. // @include https://www.themoviedb.org/tv/*
  68. // @include http://letterboxd.com/film/*
  69. // @include https://letterboxd.com/film/*
  70. // @include http://www.tvmaze.com/shows/*
  71. // @include http://www.tvguide.com/tvshows/*
  72. // @include https://www.tvguide.com/tvshows/*
  73. // @include http://followshows.com/show/*
  74. // @include https://followshows.com/show/*
  75. // @include http://thetvdb.com/*tab=series*
  76. // @include https://thetvdb.com/*tab=series*
  77. // @include http://www.thetvdb.com/*tab=series*
  78. // @include https://www.thetvdb.com/*tab=series*
  79. // @include https://www.thetvdb.com/series/*
  80. // @include http://consequenceofsound.net/*
  81. // @include https://consequenceofsound.net/*
  82. // @include http://pitchfork.com/*
  83. // @include https://pitchfork.com/*
  84. // @include http://www.last.fm/*
  85. // @include https://www.last.fm/*
  86. // @include http://tvnfo.com/s/*
  87. // @include https://tvnfo.com/s/*
  88. // @include http://rateyourmusic.com/release/album/*
  89. // @include https://rateyourmusic.com/release/album/*
  90. // @include https://open.spotify.com/*
  91. // @include https://play.spotify.com/album/*
  92. // @include https://www.nme.com/reviews/*
  93. // @include https://www.albumoftheyear.org/album/*
  94. // ==/UserScript==
  95.  
  96.  
  97. var baseURL = "https://www.metacritic.com/";
  98.  
  99. var baseURL_music = "https://www.metacritic.com/music/";
  100. var baseURL_movie = "https://www.metacritic.com/movie/";
  101. var baseURL_pcgame = "https://www.metacritic.com/game/pc/";
  102. var baseURL_ps4 = "https://www.metacritic.com/game/playstation-4/";
  103. var baseURL_xone = "https://www.metacritic.com/game/xbox-one/";
  104. var baseURL_tv = "https://www.metacritic.com/tv/";
  105.  
  106. var baseURL_search = "https://www.metacritic.com/search/{type}/{query}/results";
  107. var baseURL_autosearch = "https://www.metacritic.com/autosearch";
  108.  
  109. var baseURL_database = "https://php-cuzi.herokuapp.com/r.php";
  110. var baseURL_whitelist = "https://php-cuzi.herokuapp.com/whitelist.php";
  111. var baseURL_blacklist = "https://php-cuzi.herokuapp.com/blacklist.php";
  112.  
  113. // http://www.designcouch.com/home/why/2013/05/23/dead-simple-pure-css-loading-spinner/
  114. 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%}";
  115.  
  116. function getHostname(url) {
  117. with(document.createElement("a")) {
  118. href = url;
  119. return hostname;
  120. }
  121. }
  122. function absoluteMetaURL(url) {
  123. if(url.startsWith("https://")) {
  124. return url;
  125. }
  126. if(url.startsWith("http://")) {
  127. return "https" + url.substr(4);
  128. }
  129. if(url.startsWith("//")) {
  130. return baseURL + url.substr(2);
  131. }
  132. if(url.startsWith("/")) {
  133. return baseURL + url.substr(1);
  134. }
  135. return baseURL + url;
  136. }
  137.  
  138. function parseLDJSON(keys, condition) {
  139. if(document.querySelector('script[type="application/ld+json"]')) {
  140. var data = [];
  141. var scripts = document.querySelectorAll('script[type="application/ld+json"]');
  142. for(let i = 0; i < scripts.length; i++) {
  143. try {
  144. var jsonld = JSON.parse(scripts[i].innerText);
  145. } catch(e) {
  146. continue;
  147. }
  148. if(jsonld) {
  149. if(Array.isArray(jsonld)) {
  150. data.push(...jsonld)
  151. } else {
  152. data.push(jsonld);
  153. }
  154. }
  155. }
  156. for(let i = 0; i < data.length; i++) {
  157. try {
  158. if(data[i] && data[i] && (typeof condition != 'function' || condition(data[i]))) {
  159. if(Array.isArray(keys)) {
  160. let r = [];
  161. for(let j = 0; j < keys.length; j++) {
  162. r.push(data[i][keys[j]]);
  163. }
  164. return r;
  165. } else if(keys) {
  166. return data[i][keys];
  167. } else if(typeof condition === 'function') {
  168. return data[i]; // Return whole object
  169. }
  170. }
  171. } catch(e) {
  172. continue;
  173. }
  174. }
  175. return data;
  176. }
  177. return null;
  178. }
  179.  
  180.  
  181. function name2metacritic(s) {
  182. return s.normalize('NFKD').replace(/\//g,"").replace(/[\u0300-\u036F]/g, '').replace(/&/g,"and").replace(/\W+/g, " ").toLowerCase().trim().replace(/\W+/g,"-");
  183. }
  184. function minutesSince(time) {
  185. var seconds = ((new Date()).getTime() - time.getTime()) / 1000;
  186. return seconds>60?parseInt(seconds/60)+" min ago":"now";
  187. }
  188. function randomStringId() {
  189. var id10 = () => Math.floor((1 + Math.random()) * 0x10000000000).toString(16).substring(1);
  190. return id10()+id10()+id10()+id10()+id10()+id10();
  191. }
  192. function fixMetacriticURLs(html) {
  193. return html.replace(/<a /g,'<a target="_blank" ').replace(/href="\//g,'href="'+baseURL).replace(/src="\//g,'src="'+baseURL);
  194. }
  195. function searchType2metacritic(type) {
  196. return ({
  197. 'movie' : 'movie',
  198. 'pcgame' : 'game',
  199. 'xonegame' : 'game',
  200. 'ps4game' : 'game',
  201. 'music' : 'album',
  202. 'tv' : 'tv'
  203. })[type];
  204. }
  205. function metacritic2searchType(type) {
  206. return ({
  207. "Album" : "music",
  208. "TV" : "tv",
  209. "Movie" : "movie",
  210. "PC Game" : "pcgame",
  211. "PS4 Game" : "ps4game",
  212. "XONE Game" : "onegame",
  213. "WIIU Game" : "xxxxx",
  214. "3DS Game" : "xxxx"
  215. })[type];
  216. }
  217.  
  218.  
  219. function metaScore(score, word) {
  220. var fg,bg,t;
  221. if(score == null) {
  222. fg = "black";
  223. bg = "#ccc";
  224. t = "tbd";
  225. } else if(score >= 75) {
  226. fg = "white";
  227. bg = "#6c3";
  228. t = parseInt(score);
  229. } else if(score < 40) {
  230. fg = "white";
  231. bg = "#f00";
  232. t = parseInt(score);
  233. } else {
  234. fg = "white";
  235. bg = "#fc3";
  236. t = parseInt(score);
  237. }
  238. 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>';
  239. }
  240.  
  241. function balloonAlert(message, timeout, title, css, click) {
  242. var header;
  243. if(title) {
  244. header = '<div style="background:rgb(220,230,150); padding: 2px 12px;">' + title +"</div>";
  245. } else if(title === false) {
  246. header = '';
  247. } else {
  248. header = '<div style="background:rgb(220,230,150); padding: 2px 12px;">Userscript alert</div>';
  249. }
  250. var div = $("<div>" + header + '<div style="padding:5px">' + message.split("\n").join("<br>") + "</div></div>");
  251. div.css({
  252. position : "fixed",
  253. top : 10,
  254. left : 10,
  255. maxWidth: 200,
  256. zIndex : "5010002",
  257. background : "rgb(240,240,240)",
  258. border : "2px solid yellow",
  259. borderRadius :"6px",
  260. boxShadow: "0 0 3px 3px rgba(100, 100, 100, 0.2)",
  261. fontFamily: "sans-serif",
  262. color: "black"
  263. });
  264. if(css) {
  265. div.css(css);
  266. }
  267. div.appendTo(document.body);
  268. if(click) {
  269. div.click(function(ev) {
  270. $(this).hide(500);
  271. click.call(this,ev);
  272. });
  273. }
  274. if(!click) {
  275. var close = $('<div title="Close" style="cursor:pointer; position:absolute; top:0px; right:3px;">&#10062;</div>').appendTo(div);
  276. close.click(function(){
  277. $(this.parentNode).hide(1000);
  278. });
  279. }
  280. if(timeout && timeout > 0) {
  281. window.setTimeout(function() {
  282. div.hide(3000);
  283. }, timeout);
  284. }
  285. return div;
  286. }
  287.  
  288.  
  289. function filterUniversalUrl(url) {
  290. try {
  291. url = url.match(/http.+/)[0];
  292. } catch(e) { }
  293. try {
  294. url = url.replace(/https?:\/\/(www.)?/,"");
  295. } catch(e) { }
  296. if(url.startsWith("imdb.com/") && url.match(/(imdb\.com\/\w+\/\w+\/)/)) {
  297. // Remove movie subpage from imdb url
  298. return url.match(/(imdb\.com\/\w+\/\w+\/)/)[1];
  299. } else if(url.startsWith("thetvdb.com/")) {
  300. // Do nothing with thetvdb.com urls
  301. return url;
  302. } else if(url.startsWith("boxofficemojo.com/")) {
  303. // Keep the important id= on
  304. try {
  305. var parts = url.split("?");
  306. var page = url[0] + "?";
  307. var idparam = url[1].match(/(id=.+?)(\.|&)/)[1];
  308. return page+idparam;
  309. } catch(e) {
  310. return url;
  311. }
  312. } else {
  313. // Default: Remove parameters
  314. return url.split("?")[0].split("&")[0];
  315. }
  316. }
  317.  
  318. async function addToMap(url, metaurl) {
  319. var data = JSON.parse(await GM.getValue("map","{}"));
  320. var url = filterUniversalUrl(url);
  321. var metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//,"");
  322.  
  323. data[url] = metaurl;
  324. await GM.setValue("map", JSON.stringify(data));
  325. (new Image()).src = baseURL_whitelist + "?docurl="+encodeURIComponent(url)+"&metaurl="+encodeURIComponent(metaurl)+"&ref="+encodeURIComponent(randomStringId());
  326. return [url, metaurl];
  327. }
  328.  
  329. async function addToBlacklist(url, metaurl) {
  330. var data = JSON.parse(await GM.getValue("black","[]"));
  331. var url = filterUniversalUrl(url);
  332. var metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//,"");
  333.  
  334. data.push([url,metaurl]);
  335. await GM.setValue("black", JSON.stringify(data));
  336. (new Image()).src = baseURL_blacklist + "?docurl="+encodeURIComponent(url)+"&metaurl="+encodeURIComponent(metaurl)+"&ref="+encodeURIComponent(randomStringId());
  337. return [url, metaurl];
  338. }
  339.  
  340.  
  341.  
  342.  
  343. async function isBlacklistedUrl(docurl, metaurl) {
  344.  
  345. docurl = filterUniversalUrl(docurl);
  346. docurl = docurl.replace(/https?:\/\/(www.)?/,"");
  347. metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//,"");
  348. metaurl = metaurl.replace(/\/\//g,"/").replace(/\/\//g,"/");; // remove double slash
  349. metaurl = metaurl.replace(/^\/+/,""); // remove starting slash
  350. var data = JSON.parse(await GM.getValue("black","[]")); // [ [docurl0, metaurl0] , [docurl1, metaurl1] , ... ]
  351. for(var i = 0; i < data.length; i++) {
  352. if(data[i][0] == docurl && data[i][1] == metaurl) {
  353. return true;
  354. }
  355. }
  356. return false;
  357. }
  358.  
  359. async function isBlacklisted(metaurl) {
  360. return await isBlacklistedUrl("" + document.location.host.replace(/^www\./,"") + document.location.pathname + document.location.search, metaurl);
  361. }
  362.  
  363.  
  364.  
  365. function listenForHotkeys(code, cb) {
  366. // Call cb() as soon as the code sequence was typed
  367. var i = 0;
  368. $(document).bind("keydown.listenForHotkeys",function(ev) {
  369. if(document.activeElement == document.body) {
  370. if(ev.key != code[i]) {
  371. i = 0;
  372. } else {
  373. i++;
  374. if(i == code.length) {
  375. ev.preventDefault();
  376. $(document).unbind("keydown.listenForHotkeys");
  377. cb();
  378. }
  379. }
  380. }
  381. });
  382. }
  383.  
  384.  
  385. async function metacritic_hoverInfo(url, docurl, cb, errorcb, nocache) {
  386. // Get the metacritic hover info. Requests are cached.
  387. var handleresponse = function(response, cached) {
  388. if(response.status == 200 && response.responseText && cb) {
  389. if(~response.responseText.indexOf('"jsonRedirect"')) { // {"viewer":{},"mixpanelToken":"6e219fd....","mixpanelDistinctId":"255.255.255.255","omnitureDebug":0,"jsonRedirect":"\/movie\/national-lampoons-vacation"}
  390. var blacklistedredirect = false;
  391. var j = JSON.parse(response.responseText);
  392. current.url = absoluteMetaURL(j["jsonRedirect"]);
  393. delete cache[url]; // Delete original url from cache. The redirect URL will then be saved in metacritic_hoverInfo(...)
  394.  
  395. // Blacklist items from database received?
  396. if("blacklist" in j && j.blacklist && j.blacklist.length) {
  397. // Save new blacklist items
  398. GM.getValue("black","[]").then(function(json_data) {
  399. var data = JSON.parse(json_data);
  400. for(var i = 0; i < j.blacklist.length; i++) {
  401. var save_docurl = j.blacklist[i].docurl;
  402. var save_metaurl = j.blacklist[i].metaurl;
  403. data.push([save_docurl,save_metaurl]);
  404. if(j["jsonRedirect"] == "/"+save_metaurl) {
  405. // Redirect is blacklisted!
  406. blacklistedredirect = true;
  407. }
  408. }
  409. GM.setValue("black", JSON.stringify(data));
  410. });
  411. }
  412. if(blacklistedredirect && errorcb) {
  413. // Redirect was blacklisted, show nothing
  414. errorcb(response.responseText, new Date(response.time));
  415. } else {
  416. // Load redirect
  417. metacritic_hoverInfo(absoluteMetaURL(j["jsonRedirect"]), false, cb, errorcb, true);
  418. }
  419. } else {
  420. // Show
  421. cb(response.responseText, new Date(response.time));
  422. }
  423. } else if(response.status != 200 && errorcb) {
  424. errorcb(response.responseText, new Date(response.time));
  425. if(!cached)
  426. console.log("Show metacritic ratings: Error 01:"+response.status+"\n"+url);
  427. } else if(!response.responseText) {
  428. errorcb("", new Date(response.time));
  429. if(!cached)
  430. console.log("Show metacritic ratings: Error 02: response empty. Status:"+response.status+"\n"+url);
  431. }
  432. };
  433.  
  434. var cache = JSON.parse(await GM.getValue("hovercache","{}"));
  435. for(var prop in cache) {
  436. // Delete cached values, that are older than 2 hours
  437. if((new Date()).getTime() - (new Date(cache[prop].time)).getTime() > 2*60*60*1000) {
  438. delete cache[prop];
  439. }
  440. }
  441. if(!nocache && url in cache) {
  442. handleresponse(cache[url], true);
  443. } else {
  444. var requestURL = url;
  445. var requestParams = "hoverinfo=1";
  446. if(docurl && docurl.indexOf("metacritic.com") == -1 && docurl.indexOf(baseURL_database) == -1) {
  447. // Ask database for correct metacritic entry:
  448. requestURL = baseURL_database;
  449. requestParams = "m=" + encodeURIComponent(docurl) + "&a=" + encodeURIComponent(url);
  450. }
  451. GM.xmlHttpRequest({
  452. method: "POST",
  453. url: requestURL,
  454. data: requestParams,
  455. headers: {
  456. "Referer" : url,
  457. "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8",
  458. "Host" : getHostname(requestURL), // This is important, otherwise Metacritic refuses to answer!
  459. //"User-Agent" : "MetacriticUserscript "+navigator.userAgent,
  460. "User-Agent" : navigator.userAgent,
  461. "X-Requested-With" : "XMLHttpRequest"
  462. },
  463. onload: async function(response) {
  464. response.time = (new Date()).toJSON();
  465. // Chrome fix: Otherwise JSON.stringify(cache) omits responseText
  466. var newobj = {};
  467. for(var key in response) {
  468. newobj[key] = response[key];
  469. }
  470. newobj.responseText = response.responseText.substr(0); // Create a copy of the string
  471.  
  472. cache[url] = newobj;
  473. await GM.setValue("hovercache",JSON.stringify(cache));
  474. handleresponse(response, false);
  475. },
  476. onerror: function(response) {
  477. console.log("Show metacritic ratings: Hover info error 03: "+response.status+"\nURL: "+requestURL+"\nResponse:\n"+response.responseText);
  478. },
  479. });
  480. }
  481. }
  482. async function metacritic_searchResults(url, cb, errorcb) {
  483. // Get metacritic search results. Requests are cached.
  484. var handleresponse = function(response, cached) {
  485. if(response.results.length && cb) {
  486. cb(response.results, new Date(response.time));
  487. } else if(response.results.length == 0 && errorcb) {
  488. errorcb(response.results, new Date(response.time));
  489. }
  490. };
  491. var cache = JSON.parse(await GM.getValue("searchcache","{}"));
  492. for(var prop in cache) {
  493. // Delete cached values, that are older than 2 hours
  494. if((new Date()).getTime() - (new Date(cache[prop].time)).getTime() > 2*60*60*1000) {
  495. delete cache[prop];
  496. }
  497. }
  498. if(url in cache) {
  499. handleresponse(cache[url], true);
  500. } else {
  501. GM.xmlHttpRequest({
  502. method: "GET",
  503. url: url,
  504. headers: {
  505. "Referer" : url,
  506. "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8",
  507. "Host" : "www.metacritic.com",
  508. "User-Agent" : "MetacriticUserscript "+navigator.userAgent,
  509. },
  510. onload: async function(response) {
  511. var results = [];
  512. if(!~response.responseText.indexOf("No search results found.")) {
  513. var d = $('<html>').html(response.responseText);
  514. d.find("ul.search_results.module .result").each(function() {
  515. results.push(this.innerHTML);
  516. });
  517. }
  518.  
  519. response = {
  520. time : (new Date()).toJSON(),
  521. results : results,
  522. };
  523. cache[url] = response;
  524. await GM.setValue("searchcache",JSON.stringify(cache));
  525. handleresponse(response, false);
  526. },
  527. onerror: function(response) {
  528. console.log("Show metacritic ratings: Search error 04: "+response.status+"\n"+url);
  529. handleresponse({
  530. time : (new Date()).toJSON(),
  531. results : [],
  532. }, false);
  533. }
  534. });
  535. }
  536. }
  537.  
  538. function metacritic_showHoverInfo(url, docurl) {
  539. if(!url) {
  540. return;
  541. }
  542. metacritic_hoverInfo(url, docurl?docurl:false,
  543. // On Success
  544. function(html, time) {
  545. $("#mcdiv123").remove();
  546. var div = $('<div id="mcdiv123"></div>').appendTo(document.body);
  547. div.css({
  548. position:"fixed",
  549. bottom :0,
  550. left: 0,
  551. minWidth: 300,
  552. backgroundColor: "#fff",
  553. border: "2px solid #bbb",
  554. borderRadius:" 6px",
  555. boxShadow: "0 0 3px 3px rgba(100, 100, 100, 0.2)",
  556. color: "#000",
  557. padding:" 3px",
  558. zIndex: "5010001",
  559. });
  560. // Functions for communication between page and iframe
  561. // Mozilla can access parent.document
  562. // Chrome can use postMessage()
  563. var frame_status = false; // if this remains false, loading the frame content failed. A reason could be "Content Security Policy"
  564. function loadExternalImage(url, myframe) {
  565. // Load external image, bypass CSP
  566. GM.xmlHttpRequest({
  567. method: "GET",
  568. url: url,
  569. responseType : "arraybuffer",
  570. onload: function(response) {
  571. myframe.contentWindow.postMessage({
  572. "mcimessage_imgLoaded" : true,
  573. "mcimessage_imgData" : response.response,
  574. "mcimessage_imgOrgSrc" : url
  575. },'*');
  576. }
  577. });
  578. }
  579. var functions = {
  580. "parent" : function() {
  581. var f = parent.document.getElementById('mciframe123');
  582. var lastdiff = -200000;
  583. window.addEventListener("message", function(e){
  584. if(typeof e.data != "object") {
  585. return;
  586. } else if("mcimessage0" in e.data) {
  587. frame_status = true; // Frame content was loaded successfully
  588. } else if("mcimessage1" in e.data) {
  589. f.style.width = parseInt(f.style.width)+10+"px";
  590. if(e.data.heightdiff == lastdiff) {
  591. f.style.height = parseInt(f.style.height)+5+"px";
  592. }
  593. lastdiff = e.data.heightdiff;
  594. } else if("mcimessage2" in e.data) {
  595. f.style.height = parseInt(f.style.height)+15+"px";
  596. f.style.width = "400px";
  597. } else if("mcimessage_loadImg" in e.data) {
  598. loadExternalImage(e.data.mcimessage_imgUrl, f);
  599. } else {
  600. return;
  601. }
  602. f.contentWindow.postMessage({
  603. "mcimessage3" : true,
  604. "mciframe123_clientHeight" : f.clientHeight,
  605. "mciframe123_clientWidth" : f.clientWidth,
  606. },'*');
  607. });
  608. },
  609. "frame" : function() {
  610. parent.postMessage({"mcimessage0":true},'*'); // Loading frame content was successfull
  611. var i = 0;
  612. window.addEventListener("message", function(e){
  613. if(typeof e.data == "object" && "mcimessage_imgLoaded" in e.data) {
  614. // Load external image
  615. var arrayBufferView = new Uint8Array( e.data["mcimessage_imgData"] );
  616. var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
  617. var urlCreator = window.URL || window.webkitURL;
  618. var imageUrl = urlCreator.createObjectURL( blob );
  619. var img = failedImages[e.data["mcimessage_imgOrgSrc"]];
  620. img.src = imageUrl;
  621. }
  622. if(!("mcimessage3" in e.data)) return;
  623. if(e.data.mciframe123_clientHeight < document.body.scrollHeight && i < 100) {
  624. parent.postMessage({"mcimessage1":1, "heightdiff":document.body.scrollHeight - e.data.mciframe123_clientHeight},'*');
  625. i++;
  626. }
  627. if(i >= 100) {
  628. parent.postMessage({"mcimessage2":1},'*')
  629. i = 0;
  630. }
  631. });
  632. parent.postMessage({"mcimessage1":1,"heightdiff":-100000},'*');
  633. }
  634. };
  635.  
  636. var css = "#hover_div .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;} #hover_div .hoverinfo .hover_left { float: left} #hover_div .hoverinfo .product_image_wrapper { color: #999; font-size: 6px; font-weight: normal; min-height: 98px; min-width: 98px;} #hover_div .hoverinfo .product_image_wrapper a { color: #999; font-size: 6px; font-weight: normal;} #hover_div a * { cursor: pointer} #hover_div a { color: #09f; font-weight: bold;} #hover_div a:link, #hover_div a:visited { text-decoration: none;} #hover_div a:hover { text-decoration: underline;} #hover_div .hoverinfo .hover_right { float: left; margin-left: 15px; max-width: 395px;} #hover_div .hoverinfo .product_title { color: #333; font-family: georgia,serif; font-size: 24px; line-height: 26px; margin-bottom: 10px;} #hover_div .hoverinfo .product_title a { color:#333; font-family: georgia,serif; font-size: 24px;} #hover_div .hoverinfo .summary_detail.publisher, .hoverinfo .summary_detail.release_data { float: left} #hover_div .hoverinfo .summary_detail { font-size: 11px; margin-bottom: 10px;} #hover_div .hoverinfo .summary_detail.product_credits a { color: #999; font-weight: normal; } #hover_div .hoverinfo .hr { background-color: #ccc; height: 2px; margin: 15px 0 10px;} #hover_div .hoverinfo .hover_scores { width: 100%; border-collapse: collapse; border-spacing: 0;} #hover_div .hoverinfo .hover_scores td.num { width: 39px} #hover_div .hoverinfo .hover_scores td { vertical-align: middle} #hover_div caption, #hover_div th, #hover_div td { font-weight: normal; text-align: left;} #hover_div .metascore_anchor, #hover_div a.metascore_w { text-decoration: none !important} #hover_div span.metascore_w, #hover_div a.metascore_w { display: inline-block; padding:0px;}.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;} #hover_div .metascore, #hover_div .metascore a, #hover_div .avguserscore, #hover_div .avguserscore a { color: #fff} #hover_div .critscore, #hover_div .critscore a, #hover_div .userscore, #hover_div .userscore a { color: #333}.score_tbd { background: #eaeaea; color: #333; font-size: 14px;} #hover_div .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;} #hover_div .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.album { padding-top:0px; !important} .metascore_w.user { border-radius: 55%; color: #fff;}.metascore_anchor, .metascore_w.album { padding: 0px;!important, padding-top: 0px;!important} 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;}";
  637.  
  638. var framesrc = 'data:text/html,';
  639. framesrc += encodeURIComponent('<!DOCTYPE html>\
  640. <html lang="en">\
  641. <head>\
  642. <meta charset="utf-8">\
  643. <title>Metacritic info</title>\
  644. <style>body { margin:0px; padding:0px; background:white; }' + css
  645. +'\
  646. </style>\
  647. <script>\
  648. var failedImages = {};\
  649. function detectCSP(img) {\
  650. if(img.complete && (!img.naturalWidth || !img.naturalHeight)) {\
  651. return true;\
  652. }\
  653. return false;\
  654. }\
  655. function findCSPerrors() {\
  656. var imgs = document.querySelectorAll("img");\
  657. for(var i = 0; i < imgs.length; i++) {\
  658. if(imgs[i].complete && detectCSP(imgs[i])) {\
  659. fixCSP(imgs[i]);\
  660. }\
  661. }\
  662. }\
  663. function fixCSP(img) {\
  664. console.log("Loading image failed. Bypassing CSP...");\
  665. failedImages[img.src] = img;\
  666. parent.postMessage({"mcimessage_loadImg":true, "mcimessage_imgUrl": img.src},"*"); \
  667. }\
  668. function on_load() {\
  669. ('+functions.frame.toString()+')();\
  670. window.setTimeout(findCSPerrors, 500);\
  671. \
  672. }\
  673. </script>\
  674. </head>\
  675. <body onload="on_load();">\
  676. <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">\
  677. <div class="hover_content">'+fixMetacriticURLs(html)+'</div>\
  678. </div>\
  679. </body>\
  680. </html>');
  681. var frame = $("<iframe></iframe>").appendTo(div);
  682. frame.attr("id","mciframe123");
  683. frame.attr("src",framesrc);
  684. frame.attr("scrolling","auto");
  685. frame.css({
  686. width: 400,
  687. height: 170,
  688. border: "none"
  689. });
  690. window.setTimeout(function() {
  691. if(!frame_status) { // Loading frame content failed.
  692. // Directly inject the html without an iframe (this may break the site or the metacritic)
  693. console.log("Loading iframe content failed. Injecting directly.");
  694. $("head").append("<style>"+css+"</style>");
  695. var noframe = $('<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">\
  696. <div class="hover_content">'+fixMetacriticURLs(html)+'</div>\
  697. </div>');
  698. frame.replaceWith(noframe);
  699. }
  700. },2000);
  701. functions.parent();
  702. var sub = $("<div></div>").appendTo(div);
  703. $('<time style="color:#b6b6b6; font-size: 11px;" datetime="'+time+'" title="'+time.toLocaleTimeString()+" "+time.toLocaleDateString()+'">'+minutesSince(time)+'</time>').appendTo(sub);
  704. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="'+url+'" title="Open Metacritic">'+decodeURI(url.replace("https://www.","@"))+'</a>').appendTo(sub);
  705. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px; padding-left:5px;">&#10062;</span>').appendTo(sub).click(function() {
  706. document.body.removeChild(this.parentNode.parentNode);
  707. });
  708. $('<span title="Assist us: This is the correct entry!" style="cursor:pointer; float:right; color:green; font-size: 11px;">&check;</span>').data("url", url).appendTo(sub).click(function() {
  709. var docurl = document.location.href;
  710. var metaurl = $(this).data("url");
  711. addToMap(docurl, metaurl).then(function(r) {
  712. balloonAlert("Thanks for your submission!\n\nSaved as a correct entry.\n\n"+r[0]+"\n"+r[1], 6000, "Success");
  713. });
  714. });
  715. $('<span title="Assist us: 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() {
  716. if(!confirm("This is NOT the correct entry!\n\nAdd to blacklist?")) return;
  717. var docurl = document.location.href;
  718. var metaurl = $(this).data("url");
  719. addToBlacklist(docurl,metaurl).then(function(r) {
  720. balloonAlert("Thanks for your submission!\n\nSaved to blacklist.\n\n"+r[0]+"\n"+r[1], 6000, "Success");
  721. });
  722.  
  723. // Open search
  724. metacritic_searchcontainer(null, current.searchTerm);
  725. metacritic_search(null, current.searchTerm);
  726. });
  727.  
  728. },
  729. // On error i.e. no result on metacritic.com
  730. async function(html, time) {
  731. // Make search available
  732. metacritic_waitForHotkeys();
  733. var handleresponse = await async function(response, fromcache) {
  734. var data;
  735. var multiple = false;
  736. try {
  737. data = JSON.parse(response.responseText);
  738. } catch(e) {
  739. console.log("Error in JSON 05: search_term="+current.searchTerm);
  740. console.log(e);
  741. }
  742. if(data && data.autoComplete && data.autoComplete.results && data.autoComplete.results.length) {
  743. // Remove data with wrong type
  744. data.autoComplete = data.autoComplete.results;
  745. var newdata = [];
  746. data.autoComplete.forEach(function(result) {
  747. if(metacritic2searchType(result.refType) == current.type) {
  748. newdata.push(result);
  749. }
  750. });
  751. data.autoComplete = newdata;
  752. if(data.autoComplete.length == 0) {
  753. // No results
  754. console.log("No results (after filtering by type) for search_term="+current.searchTerm);
  755. } else if(data.autoComplete.length == 1) {
  756. // One result, let's show it
  757. if(! await isBlacklisted(absoluteMetaURL(data.autoComplete[0].url))) {
  758. metacritic_showHoverInfo(absoluteMetaURL(data.autoComplete[0].url));
  759. return;
  760. }
  761. } else {
  762. // More than one result
  763. multiple = true;
  764. console.log("Multiple results for search_term="+current.searchTerm);
  765. var exactMatches = [];
  766. data.autoComplete.forEach(function(result,i) { // Try to find the correct result by matching the search term to exactly one movie title
  767. if(current.searchTerm == result.name) {
  768. exactMatches.push(result);
  769. }
  770. });
  771. if(exactMatches.length == 1) {
  772. // Only one exact match, let's show it
  773. console.log("Only one exact match for search_term="+current.searchTerm);
  774. if(! await isBlacklisted(absoluteMetaURL(exactMatches[0].url))) {
  775. metacritic_showHoverInfo(absoluteMetaURL(exactMatches[0].url));
  776. return;
  777. }
  778. }
  779. }
  780. } else {
  781. console.log("No results (at all) for search_term="+current.searchTerm);
  782. }
  783. // HERE: multiple results or no result. The user may type "meta" now
  784. if(multiple) {
  785. balloonAlert("Multiple metacritic results. Type &#34;meta&#34; for manual search.", 10000, false, {bottom: 5, top:"auto", maxWidth: 400, paddingRight: 5}, metacritic_searchcontainer);
  786. }
  787. };
  788. var cache = JSON.parse(await GM.getValue("autosearchcache","{}"));
  789. for(var prop in cache) {
  790. // Delete cached values, that are older than 2 hours
  791. if((new Date()).getTime() - (new Date(cache[prop].time)).getTime() > 2*60*60*1000) {
  792. delete cache[prop];
  793. }
  794. }
  795. if(current.type == "music") {
  796. current.searchTerm = current.data[0];
  797. } else {
  798. current.searchTerm = current.data.join(" ");
  799. }
  800. if(current.searchTerm in cache) {
  801. handleresponse(cache[current.searchTerm], true);
  802. } else {
  803. GM.xmlHttpRequest({
  804. method: "POST",
  805. url: baseURL_autosearch,
  806. data: "search_term="+encodeURIComponent(current.searchTerm)+"&image_size=98&search_each=1&sort_type=popular",
  807. headers: {
  808. "Referer" : url,
  809. "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8",
  810. "Host" : "www.metacritic.com",
  811. "User-Agent" : "MetacriticUserscript Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0",
  812. "X-Requested-With" : "XMLHttpRequest"
  813. },
  814. onload: async function(response) {
  815. response = {
  816. time : (new Date()).toJSON(),
  817. responseText : response.responseText.substr(0), // Chrome fix: Otherwise JSON.stringify(cache) omits responseText
  818. };
  819. cache[current.searchTerm] = response;
  820. await GM.setValue("autosearchcache",JSON.stringify(cache));
  821. handleresponse(response, false);
  822. }
  823. });
  824. }
  825. });
  826. }
  827.  
  828. function metacritic_waitForHotkeys() {
  829. listenForHotkeys("meta",metacritic_searchcontainer);
  830. }
  831.  
  832. function metacritic_searchcontainer(ev, query) {
  833. if(!query) {
  834. if(current.type == "music") {
  835. query = current.data[0];
  836. } else {
  837. query = current.data.join(" ");
  838. }
  839. }
  840. $("#mcdiv123").remove();
  841. var div = $('<div id="mcdiv123"></div>').appendTo(document.body);
  842. div.css({
  843. position:"fixed",
  844. bottom :0,
  845. left: 0,
  846. minWidth: 300,
  847. maxHeight: "80%",
  848. maxWidth: 640,
  849. overflow:"auto",
  850. backgroundColor: "#fff",
  851. border: "2px solid #bbb",
  852. borderRadius:" 6px",
  853. boxShadow: "0 0 3px 3px rgba(100, 100, 100, 0.2)",
  854. color: "#000",
  855. padding:" 3px",
  856. zIndex: "5010001",
  857. });
  858. var query = $('<input type="text" size="60" id="mcisearchquery" style="background:white;color:black;">').appendTo(div).focus().val(query).on('keypress', function(e) {
  859. var code = e.keyCode || e.which;
  860. if(code == 13) { // Enter key
  861. metacritic_search.call(this,e);
  862. }
  863. });
  864. $('<button id="mcisearchbutton" style="background:silver;color:black;">').text("Search").appendTo(div).click(metacritic_search);
  865. }
  866.  
  867.  
  868. function metacritic_search(ev, query) {
  869. if(!query) { // Use values from search form
  870. query = $("#mcisearchquery").val();
  871. }
  872. var type = searchType2metacritic(current.type);
  873.  
  874. var style = document.createElement('style');
  875. style.type = 'text/css';
  876. style.innerHTML = CSS;
  877. document.head.appendChild(style);
  878.  
  879. var div = $("#mcdiv123");
  880. var loader = $('<div style="width:20px; height:20px;" class="grespinner"></div>').appendTo($("#mcisearchbutton"));
  881. var url = baseURL_search.replace("{type}",encodeURIComponent(type)).replace("{query}",encodeURIComponent(query));
  882.  
  883. metacritic_searchResults(url,
  884. // On success
  885. function(results, time) {
  886. loader.remove();
  887. var accept = function(ev) {
  888. var a = $(this.parentNode).find("a[href*='metacritic.com']");
  889. var metaurl = a.attr("href");
  890. var docurl = document.location.href;
  891.  
  892. addToMap(docurl,metaurl).then(function() {
  893. metacritic_showHoverInfo(metaurl);
  894. });
  895. };
  896. var denyAll = function(ev) {
  897. var urls = [];
  898. var docurl = document.location.href;
  899. $("#mcdiv123searchresults").find("div.result a[href*='metacritic.com']").each(function() {
  900. addToBlacklist(docurl, this.href);
  901. });
  902. };
  903. var resultdiv = $("#mcdiv123searchresults").length?$("#mcdiv123searchresults").html(""):$('<div id="mcdiv123searchresults"></div>').css("max-width","95%").appendTo(div);
  904. results.forEach(function(html) {
  905. var singleresult = $('<div class="result"></div>').html(fixMetacriticURLs(html)+'<div style="clear:left"></div>').appendTo(resultdiv);
  906. $('<span title="Assist us: This is the correct entry!" style="cursor:pointer; color:green; font-size: 13px;">&check;</span>').prependTo(singleresult).click(accept);
  907. });
  908. resultdiv.find(".metascore_w.album").removeClass("album"); // Remove some classes
  909. var sub = $("<div></div>").appendTo(div);
  910. $('<time style="color:#b6b6b6; font-size: 11px;" datetime="'+time+'" title="'+time.toLocaleDateString()+'">'+minutesSince(time)+'</time>').appendTo(sub);
  911. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="'+url+'" title="Open Metacritic">'+decodeURI(url.replace("https://www.","@"))+'</a>').appendTo(sub);
  912. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px;">&#10062;</span>').appendTo(sub).click(function() {
  913. document.body.removeChild(this.parentNode.parentNode);
  914. });
  915. $('<span title="Assist us: 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()});
  916. },
  917. // On error i.e. no results
  918. function(results, time) {
  919. loader.remove();
  920. var resultdiv = $("#mcdiv123searchresults").length?$("#mcdiv123searchresults").html(""):$('<div id="mcdiv123searchresults"></div>').appendTo(div);
  921. resultdiv.html("No search results.");
  922. var sub = $("<div></div>").appendTo(div);
  923. $('<time style="color:#b6b6b6; font-size: 11px;" datetime="'+time+'" title="'+time.toLocaleDateString()+'">'+minutesSince(time)+'</time>').appendTo(sub);
  924. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="'+url+'" title="Open Metacritic">'+decodeURI(url.replace("https://www.","@"))+'</a>').appendTo(sub);
  925. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px;">&#10062;</span>').appendTo(sub).click(function() {
  926. document.body.removeChild(this.parentNode.parentNode);
  927. });
  928. }
  929. );
  930. }
  931.  
  932. var current = {
  933. url : null,
  934. type : null,
  935. data : null, // Array of raw search keys
  936. searchTerm : null
  937. };
  938.  
  939.  
  940. async function showURL(url) {
  941. if(! await isBlacklisted(url)) {
  942. var docurl = document.location.host.replace(/^www\./,"") + document.location.pathname + document.location.search;
  943. docurl = filterUniversalUrl(docurl);
  944. metacritic_showHoverInfo(url, docurl);
  945. } else {
  946. console.log(url +" is blacklisted!");
  947. }
  948. }
  949.  
  950.  
  951. var metacritic = {
  952. "mapped" : function metacritic_mapped(url, type) {
  953. // url was in the map/whitelist
  954. current.data = [url]
  955. current.url = url;
  956. current.type = type;
  957. current.searchTerm = url;
  958. showURL(url);
  959. },
  960. "music" : function metacritic_music(artistname, albumname) {
  961. current.data = [albumname.trim(),artistname.trim()]
  962. artistname = name2metacritic(artistname);
  963. albumname = albumname.replace("&"," ");
  964. albumname = name2metacritic(albumname);
  965. var url = baseURL_music + albumname + "/" + artistname;
  966. current.url = url;
  967. current.type = "music";
  968. current.searchTerm = albumname + "/" + artistname;
  969. showURL(url);
  970. },
  971. "movie" : function metacritic_movie(moviename) {
  972. current.data = [moviename.trim()]
  973. moviename = name2metacritic(moviename);
  974. var url = baseURL_movie + moviename;
  975. current.url = url;
  976. current.type = "movie";
  977. current.searchTerm = moviename;
  978. showURL(url);
  979. },
  980. "tv" : function metacritic_tv(seriesname) {
  981. current.data = [seriesname.trim()]
  982. seriesname = name2metacritic(seriesname);
  983. var url = baseURL_tv + seriesname;
  984. current.url = url;
  985. current.type = "tv";
  986. current.searchTerm = seriesname;
  987. showURL(url);
  988. },
  989. "pcgame" : function metacritic_pcgame(gamename) {
  990. current.data = [gamename.trim()]
  991. gamename = name2metacritic(gamename);
  992. var url = baseURL_pcgame + gamename;
  993. current.url = url;
  994. current.type = "pcgame";
  995. current.searchTerm = gamename;
  996. showURL(url);
  997. },
  998. "ps4game" : function metacritic_ps4game(gamename) {
  999. current.data = [gamename.trim()]
  1000. gamename = name2metacritic(gamename);
  1001. var url = baseURL_ps4 + gamename;
  1002. current.url = url;
  1003. current.type = "ps4game";
  1004. current.searchTerm = gamename;
  1005. showURL(url);
  1006. },
  1007. "xonegame" : function metacritic_xonegame(gamename) {
  1008. current.data = [gamename.trim()]
  1009. gamename = name2metacritic(gamename);
  1010. var url = baseURL_xone + gamename;
  1011. current.url = url;
  1012. current.type = "xonegame";
  1013. current.searchTerm = gamename;
  1014. showURL(url);
  1015. }
  1016. };
  1017.  
  1018.  
  1019. var Always = () => true;
  1020. var sites = {
  1021. 'bandcamp' : {
  1022. host : ["bandcamp.com"],
  1023. condition : function() {
  1024. return unsafeWindow.TralbumData
  1025. },
  1026. products : [{
  1027. condition : Always,
  1028. type : "music",
  1029. data : () => [unsafeWindow.TralbumData.artist, unsafeWindow.TralbumData.current.title]
  1030. }]
  1031. },
  1032. 'itunes' : {
  1033. host : ["itunes.apple.com"],
  1034. condition : Always,
  1035. products : [{
  1036. condition : () => ~document.location.href.indexOf("/album/") ,
  1037. type : "music",
  1038. data : () => [document.querySelector("h2.t-hero-subheadline").textContent.trim(), document.querySelector("h1.t-hero-headline").textContent.trim()]
  1039. }]
  1040. },
  1041. 'googleplay' : {
  1042. host : ["play.google.com"],
  1043. condition : Always,
  1044. products : [
  1045. {
  1046. condition : () => ~document.location.href.indexOf("/album/"),
  1047. type : "music",
  1048. data : () => [document.querySelector("*[itemprop=byArtist] a").textContent, document.querySelector("*[itemprop=name]").textContent]
  1049. },
  1050. {
  1051. condition : () => ~document.location.href.indexOf("/movies/details/"),
  1052. type : "movie",
  1053. data : () => document.querySelector("*[itemprop=name]").textContent
  1054. }
  1055. ]
  1056. },
  1057. 'imdb' : {
  1058. host : ["imdb.com"],
  1059. condition : () => !~document.location.pathname.indexOf("/mediaviewer") && !~document.location.pathname.indexOf("/mediaindex") && !~document.location.pathname.indexOf("/videoplayer"),
  1060. products : [
  1061. {
  1062. condition : function() {
  1063. var e = document.querySelector("meta[property='og:type']");
  1064. if(e) {
  1065. return e.content == "video.movie"
  1066. }
  1067. return false;
  1068. },
  1069. type : "movie",
  1070. data : function() {
  1071. if(document.querySelector(".originalTitle") && document.querySelector(".title_wrapper h1")) { // Use English title 2018
  1072. return document.querySelector(".title_wrapper h1").firstChild.data.trim();
  1073. } else if(document.querySelector('script[type="application/ld+json"]')) { // Use original language title
  1074. return parseLDJSON("name");
  1075. } else if(document.querySelector("h1[itemprop=name]")) { // Movie homepage (New design 2015-12)
  1076. return document.querySelector("h1[itemprop=name]").firstChild.textContent.trim();
  1077. } else if(document.querySelector("*[itemprop=name] a") && document.querySelector("*[itemprop=name] a").firstChild.data) { // Subpage of a move
  1078. return document.querySelector("*[itemprop=name] a").firstChild.data.trim();
  1079. } else if(document.querySelector(".title-extra[itemprop=name]")) { // Movie homepage: sub-/alternative-/original title
  1080. return document.querySelector(".title-extra[itemprop=name]").firstChild.textContent.replace(/\"/g,"").trim();
  1081. } else { // Movie homepage (old design)
  1082. return document.querySelector("*[itemprop=name]").firstChild.textContent.trim();
  1083. }
  1084. }
  1085. },
  1086. {
  1087. condition : function() {
  1088. var e = document.querySelector("meta[property='og:type']");
  1089. if(e) {
  1090. return e.content == "video.tv_show"
  1091. }
  1092. return false;
  1093. },
  1094. type : "tv",
  1095. data : function() {
  1096. var year = null;
  1097. if(document.querySelector("*[itemprop=name]")) {
  1098. return document.querySelector("*[itemprop=name]").textContent;
  1099. } else {
  1100. var jsonld = JSON.parse(document.querySelector('script[type="application/ld+json"]').innerText);
  1101. return jsonld["name"];
  1102. }
  1103. }
  1104. }
  1105. ]
  1106. },
  1107. 'steam' : {
  1108. host : ["store.steampowered.com"],
  1109. condition : () => document.querySelector("*[itemprop=name]"),
  1110. products : [{
  1111. condition : Always,
  1112. type : "pcgame",
  1113. data : () => document.querySelector("*[itemprop=name]").textContent
  1114. }]
  1115. },
  1116. 'tv.com' : {
  1117. host : ["www.tv.com"],
  1118. condition : () => document.querySelector("meta[property='og:type']"),
  1119. products : [{
  1120. condition : () => document.querySelector("meta[property='og:type']").content == "tv_show" && document.querySelector("h1[data-name]"),
  1121. type : "tv",
  1122. data : () => document.querySelector("h1[data-name]").dataset.name
  1123. }]
  1124. },
  1125. 'rottentomatoes' : {
  1126. host : ["www.rottentomatoes.com"],
  1127. condition : Always,
  1128. products : [{
  1129. condition : () => document.location.pathname.startsWith("/m/"),
  1130. type : "movie",
  1131. data : () => document.querySelector("h1").firstChild.textContent
  1132. },
  1133. {
  1134. condition : () => document.location.pathname.startsWith("/tv/") ,
  1135. type : "tv",
  1136. data : () => unsafeWindow.BK.TvSeriesTitle
  1137. }
  1138. ]
  1139. },
  1140. 'serienjunkies' : {
  1141. host : ["www.serienjunkies.de"],
  1142. condition : Always,
  1143. products : [{
  1144. condition : () => Always,
  1145. type : "tv",
  1146. data : () => parseLDJSON("name", (j) => (j["@type"] == "TVSeries"))
  1147. }]
  1148. },
  1149. 'gamespot' : {
  1150. host : ["gamespot.com"],
  1151. condition : () => document.querySelector("[itemprop=device]"),
  1152. products : [
  1153. {
  1154. condition : () => ~$("[itemprop=device]").text().indexOf("PC"),
  1155. type : "pcgame",
  1156. data : () => parseLDJSON("name", (j) => (j["@type"] == "VideoGame"))
  1157. },
  1158. {
  1159. condition : () => ~$("[itemprop=device]").text().indexOf("PS4"),
  1160. type : "ps4game",
  1161. data : () => parseLDJSON("name", (j) => (j["@type"] == "VideoGame"))
  1162. },
  1163. {
  1164. condition : () => ~$("[itemprop=device]").text().indexOf("XONE"),
  1165. type : "xonegame",
  1166. data : () => parseLDJSON("name", (j) => (j["@type"] == "VideoGame"))
  1167. }
  1168. ]
  1169. },
  1170. 'amazon' : {
  1171. host : ["amazon."],
  1172. condition : Always,
  1173. products : [
  1174. {
  1175. condition : () => document.location.hostname == "music.amazon.com" && document.location.pathname.startsWith("/albums/") && document.querySelector(".viewTitle"), // "Amazon Music Unlimited" page
  1176. type : "music",
  1177. data : function() {
  1178. var artist = document.querySelector(".artistLink").textContent.trim();
  1179. var title = document.querySelector(".viewTitle").textContent.trim();
  1180. title = title.replace(/\[([^\]]*)\]/g,"").trim(); // Remove [brackets] and their content
  1181. if(artist && title) {
  1182. return [artist, title];
  1183. }
  1184. return false;
  1185. }
  1186. },
  1187. {
  1188. condition : function() { // "Normal amazon" page
  1189. try {
  1190. if(document.querySelector(".nav-categ-image").alt.toLowerCase().indexOf("musi") != -1) {
  1191. return true;
  1192. }
  1193. } catch(e) {}
  1194. var music = ["Music","Musique","Musik","Música","Musica","音楽"];
  1195. return music.some(function(s) {
  1196. if(~document.title.indexOf(s)) {
  1197. return true;
  1198. } else {
  1199. return false;
  1200. }
  1201. });
  1202. },
  1203. type : "music",
  1204. data : function() {
  1205. var artist = document.querySelector("#ProductInfoArtistLink").textContent.trim();
  1206. var title = document.querySelector("#title_feature_div").textContent.trim();
  1207. title = title.replace(/\[([^\]]*)\]/g,"").trim(); // Remove [brackets] and their content
  1208. return [artist, title];
  1209. }
  1210. },
  1211. {
  1212. condition : () => (document.getElementById("aiv-content-title") && document.getElementsByClassName("season-single-dark").length),
  1213. type : "tv",
  1214. data : () => document.getElementById("aiv-content-title").firstChild.data.trim()
  1215. },
  1216. {
  1217. condition : () => document.getElementById("aiv-content-title"),
  1218. type : "movie",
  1219. data : () => document.getElementById("aiv-content-title").firstChild.data.trim()
  1220. }
  1221. ]
  1222. },
  1223. 'BoxOfficeMojo' : {
  1224. host : ["boxofficemojo.com"],
  1225. condition : () => ~document.location.search.indexOf("id="),
  1226. products : [{
  1227. condition : () => document.querySelector("#body table:nth-child(2) tr:first-child b"),
  1228. type : "movie",
  1229. data : () => document.querySelector("#body table:nth-child(2) tr:first-child b").firstChild.data
  1230. }]
  1231. },
  1232. 'AllMovie' : {
  1233. host : ["allmovie.com"],
  1234. condition : () => document.querySelector("h2[itemprop=name].movie-title"),
  1235. products : [{
  1236. condition : () => document.querySelector("h2[itemprop=name].movie-title"),
  1237. type : "movie",
  1238. data : () => document.querySelector("h2[itemprop=name].movie-title").firstChild.data.trim()
  1239. }]
  1240. },
  1241. 'en.wikipedia' : {
  1242. host : ["en.wikipedia.org"],
  1243. condition : Always,
  1244. products : [{
  1245. condition : function() {
  1246. if(!document.querySelector(".infobox .summary")) {
  1247. return false;
  1248. }
  1249. var r = /\d\d\d\d films/;
  1250. return $("#catlinks a").filter((i,e) => e.firstChild.data.match(r)).length;
  1251. },
  1252. type : "movie",
  1253. data : () => document.querySelector(".infobox .summary").firstChild.data
  1254. },
  1255. {
  1256. condition : function() {
  1257. if(!document.querySelector(".infobox .summary")) {
  1258. return false;
  1259. }
  1260. var r = /television series/;
  1261. return $("#catlinks a").filter((i,e) => e.firstChild.data.match(r)).length;
  1262. },
  1263. type : "tv",
  1264. data : () => document.querySelector(".infobox .summary").firstChild.data
  1265. }]
  1266. },
  1267. 'movies.com' : {
  1268. host : ["movies.com"],
  1269. condition : () => document.querySelector("meta[property='og:title']"),
  1270. products : [{
  1271. condition : Always,
  1272. type : "movie",
  1273. data : () => document.querySelector("meta[property='og:title']").content
  1274. }]
  1275. },
  1276. 'themoviedb' : {
  1277. host : ["themoviedb.org"],
  1278. condition : () => document.querySelector("meta[property='og:type']"),
  1279. products : [{
  1280. condition : () => document.querySelector("meta[property='og:type']").content == "movie",
  1281. type : "movie",
  1282. data : () => document.querySelector("meta[property='og:title']").content
  1283. },
  1284. {
  1285. condition : () => document.querySelector("meta[property='og:type']").content == "tv_series",
  1286. type : "tv",
  1287. data : () => document.querySelector("meta[property='og:title']").content
  1288. }]
  1289. },
  1290. 'letterboxd' : {
  1291. host : ["letterboxd.com"],
  1292. condition : () => unsafeWindow.filmData && "name" in unsafeWindow.filmData,
  1293. products : [{
  1294. condition : Always,
  1295. type : "movie",
  1296. data : () => unsafeWindow.filmData.name
  1297. }]
  1298. },
  1299. 'TVmaze' : {
  1300. host : ["tvmaze.com"],
  1301. condition : () => document.querySelector("h1"),
  1302. products : [{
  1303. condition : Always,
  1304. type : "tv",
  1305. data : () => document.querySelector("h1").firstChild.data
  1306. }]
  1307. },
  1308. 'TVGuide' : {
  1309. host : ["tvguide.com"],
  1310. condition : Always,
  1311. products : [{
  1312. condition : () => document.location.pathname.startsWith("/tvshows/"),
  1313. type : "tv",
  1314. data : function() {
  1315. if(document.querySelector("meta[itemprop=name]")) {
  1316. return document.querySelector("meta[itemprop=name]").content;
  1317. } else {
  1318. return document.querySelector("meta[property='og:title']").content.split("|")[0];
  1319. }
  1320. }
  1321. }]
  1322. },
  1323. 'followshows' : {
  1324. host : ["followshows.com"],
  1325. condition : Always,
  1326. products : [{
  1327. condition : () => document.querySelector("meta[property='og:type']").content == "video.tv_show",
  1328. type : "tv",
  1329. data : () => document.querySelector("meta[property='og:title']").content
  1330. }]
  1331. },
  1332. 'TheTVDB' : {
  1333. host : ["thetvdb.com"],
  1334. condition : Always,
  1335. products : [{
  1336. condition : () => document.location.pathname.startsWith("/series/") || ~document.location.search.indexOf("tab=series"),
  1337. type : "tv",
  1338. data : () => document.getElementById("series_title").firstChild.data.trim()
  1339. }]
  1340. },
  1341. 'ConsequenceOfSound' : {
  1342. host : ["consequenceofsound.net"],
  1343. condition : () => document.querySelector("#main-content .review-summary"),
  1344. products : [{
  1345. condition : () => document.querySelector("#main-content .review-summary .artwork"),
  1346. type : "music",
  1347. data : function() {
  1348. var d = document.querySelector("#main-content .review-summary")
  1349. var artist = d.querySelector("a[href*='/artist/']").innerText.toLowerCase();
  1350. var album = d.querySelector("img").alt.toLowerCase().replace(artist,"").replace("-","").trim();
  1351. return [artist, album];
  1352. }
  1353. }]
  1354. },
  1355. 'Pitchfork' : {
  1356. host : ["pitchfork.com"],
  1357. condition : () => ~document.location.href.indexOf("/reviews/albums/"),
  1358. products : [{
  1359. condition : () => document.querySelector(".single-album-tombstone"),
  1360. type : "music",
  1361. data : function() {
  1362. var artist, album;
  1363. if(document.querySelector(".single-album-tombstone .artists")) {
  1364. artist = document.querySelector(".single-album-tombstone .artists").innerText.trim();
  1365. } else if(document.querySelector(".single-album-tombstone .artist-list")) {
  1366. artist = document.querySelector(".single-album-tombstone .artist-list").innerText.trim();
  1367. }
  1368. if(document.querySelector(".single-album-tombstone h1.review-title")) {
  1369. album = document.querySelector(".single-album-tombstone h1.review-title").innerText.trim();
  1370. } else if(document.querySelector(".single-album-tombstone h1")) {
  1371. album = document.querySelector(".single-album-tombstone h1").innerText.trim();
  1372. }
  1373. return [artist, album];
  1374. }
  1375. }]
  1376. },
  1377. 'Last.fm' : {
  1378. host : ["last.fm"],
  1379. condition : () => document.querySelector("*[data-page-resource-type]") && document.querySelector("*[data-page-resource-type]").dataset.pageResourceType == "album",
  1380. products : [{
  1381. condition : () => document.querySelector("*[data-page-resource-type]").dataset.pageResourceName,
  1382. type : "music",
  1383. data : function() {
  1384. var artist = document.querySelector("*[data-page-resource-type]").dataset.pageResourceArtistName;
  1385. var album = document.querySelector("*[data-page-resource-type]").dataset.pageResourceName;
  1386. return [artist, album];
  1387. }
  1388. }]
  1389. },
  1390. 'TVNfo' : {
  1391. host : ["tvnfo.com"],
  1392. condition : () => document.querySelector("#tvsign"),
  1393. products : [{
  1394. condition : Always,
  1395. type : "tv",
  1396. data : () => document.querySelector(".heading h1").textContent.trim()
  1397. }]
  1398. },
  1399. 'rateyourmusic' : {
  1400. host : ["rateyourmusic.com"],
  1401. condition : () => document.querySelector("meta[property='og:type']"),
  1402. products : [{
  1403. condition : () => document.querySelector("meta[property='og:type']").content == "music.album",
  1404. type : "music",
  1405. data : function() {
  1406. var artist = document.querySelector(".section_main_info .artist").innerText.trim();
  1407. var album = document.querySelector(".section_main_info .album_title").innerText.trim();
  1408. return [artist, album];
  1409. }
  1410. }]
  1411. },
  1412. 'spotify_webplayer' : {
  1413. host : ["open.spotify.com"],
  1414. condition : Always,
  1415. products : [{
  1416. condition : () => document.querySelector("#main .main-view-container .content.album"),
  1417. type : "music",
  1418. data : function() {
  1419. var artist = document.querySelector("#main .media-bd div a[href*='artist']").textContent;
  1420. var album = document.querySelector("#main .media-bd h2").textContent;
  1421. return [artist, album];
  1422. }
  1423. },
  1424. {
  1425. condition : () => document.location.pathname.startsWith("/album/") && document.querySelector("meta[property='og:type']").content == "music.album",
  1426. type : "music",
  1427. data : function() {
  1428. var artist = "";
  1429. var album = document.querySelector("meta[property='og:title']").content;
  1430. return [artist, album];
  1431. }
  1432. }]
  1433. },
  1434. 'spotify' : {
  1435. host : ["play.spotify.com"],
  1436. condition : Always,
  1437. products : [{
  1438. condition : () => document.location.pathname.startsWith("/album/"),
  1439. type : "music",
  1440. data : function() {
  1441. var artist = document.querySelector(".context_landing p.secondary-title").textContent;
  1442. var album = document.querySelector(".context_landing p.primary-title").textContent;
  1443. return [artist, album];
  1444. }
  1445. }]
  1446. },
  1447. 'nme' : {
  1448. host : ["nme.com"],
  1449. condition : () => document.location.pathname.startsWith("/reviews/"),
  1450. products : [
  1451. {
  1452. condition : () => document.location.pathname.startsWith("/reviews/movie/"),
  1453. type : "movie",
  1454. data : function() {
  1455. try {
  1456. return document.querySelector(".title-primary").textContent.match(/‘(.+?)’/)[1];
  1457. } catch(e) {
  1458. return document.querySelector("h1").textContent.match(/:\s*(.+)/)[1].trim();
  1459. }
  1460. }
  1461. },
  1462. {
  1463. condition : () => document.location.pathname.startsWith("/reviews/album/"),
  1464. type : "music",
  1465. data : () => document.querySelector(".title-primary").textContent.match(/\s*(.+?)\s*.\s*‘(.+?)’/).slice(1)
  1466. }]
  1467. },
  1468. 'albumoftheyear' : {
  1469. host : ["albumoftheyear.org"],
  1470. condition : Always,
  1471. products : [{
  1472. condition : () => document.location.pathname.startsWith("/album/"),
  1473. type : "music",
  1474. data : function() {
  1475. var artist = document.querySelector("*[itemprop=byArtist] *[itemprop=name]").textContent;
  1476. var album = document.querySelector(".albumTitle *[itemprop=name]").textContent;
  1477. return [artist, album];
  1478. }
  1479. }]
  1480. },
  1481. };
  1482.  
  1483.  
  1484. async function main() {
  1485. var dataFound = false;
  1486.  
  1487. var map = false;
  1488.  
  1489. for(var name in sites) {
  1490. var site = sites[name];
  1491. if(site.host.some(function(e) {return ~this.indexOf(e)}, document.location.hostname) && site.condition()) {
  1492. for(var i = 0; i < site.products.length; i++) {
  1493. if(site.products[i].condition()) {
  1494. // Check map for a match
  1495. if(map === false) {
  1496. map = JSON.parse(await GM.getValue("map","{}"));
  1497. }
  1498. var docurl = document.location.host.replace(/^www\./,"") + document.location.pathname + document.location.search;
  1499. docurl = filterUniversalUrl(docurl);
  1500. if(docurl in map) {
  1501. // Found in map, show result
  1502. var metaurl = map[docurl];
  1503. metacritic["mapped"].apply(undefined, [absoluteMetaURL(metaurl), site.products[i].type]);
  1504. break;
  1505. }
  1506. // Try to retrieve item name from page
  1507. var data;
  1508. try {
  1509. data = site.products[i].data();
  1510. } catch(e) {
  1511. data = false;
  1512. console.log(e);
  1513. }
  1514. if(data) {
  1515. metacritic[site.products[i].type].apply(undefined, Array.isArray(data)?data:[data]);
  1516. dataFound = true;
  1517. }
  1518. break;
  1519. }
  1520. }
  1521. break;
  1522. }
  1523. }
  1524. return dataFound;
  1525. }
  1526.  
  1527.  
  1528.  
  1529.  
  1530. (async function() {
  1531.  
  1532. await main();
  1533. var lastLoc = document.location.href;
  1534. var lastContent = document.body.innerText;
  1535. var lastCounter = 0;
  1536. async function newpage() {
  1537. if(lastContent == document.body.innerText && lastCounter < 15) {
  1538. window.setTimeout(newpage, 500);
  1539. lastCounter++;
  1540. } else {
  1541. lastCounter = 0;
  1542. var re = await main();
  1543. if(!re) { // No page matched or no data found
  1544. window.setTimeout(newpage, 1000);
  1545. }
  1546. }
  1547. }
  1548. window.setInterval(function() {
  1549. if(document.location.href != lastLoc) {
  1550. lastLoc = document.location.href;
  1551. $("#mcdiv123").remove();
  1552. window.setTimeout(newpage,1000);
  1553. }
  1554. },500);
  1555.  
  1556. })();