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), Steam, Gamespot (PS4, XONE, PC), Rotten Tomatoes, Serienjunkies, BoxOfficeMojo, allmovie.com, fandango.com, Wikipedia (en), themoviedb.org, letterboxd, TVmaze, TVGuide, followshows.com, TheTVDB.com, ConsequenceOfSound, Pitchfork, Last.fm, TVnfo, rateyourmusic.com, GOG, Epic Games Store

目前為 2022-04-29 提交的版本,檢視 最新版本

  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), Steam, Gamespot (PS4, XONE, PC), Rotten Tomatoes, Serienjunkies, BoxOfficeMojo, allmovie.com, fandango.com, Wikipedia (en), themoviedb.org, letterboxd, TVmaze, TVGuide, followshows.com, TheTVDB.com, ConsequenceOfSound, Pitchfork, Last.fm, TVnfo, rateyourmusic.com, GOG, Epic Games Store
  4. // @namespace cuzi
  5. // @icon https://www.metacritic.com/images/icons/metacritic-icon.svg
  6. // @supportURL https://github.com/cvzi/Metacritic-userscript/issues
  7. // @contributionURL https://buymeacoff.ee/cuzi
  8. // @contributionURL https://ko-fi.com/cuzicvzi
  9. // @grant unsafeWindow
  10. // @grant GM.xmlHttpRequest
  11. // @grant GM.setValue
  12. // @grant GM.getValue
  13. // @grant GM.registerMenuCommand
  14. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
  15. // @license GPL-3.0-or-later; https://www.gnu.org/licenses/gpl-3.0.txt
  16. // @antifeature tracking When a metacritic rating is displayed, we may store the url of the current website and the metacritic url in our database. Log files are temporarily retained by our database hoster heroku.com and contain your IP address and browser configuration.
  17. // @version 78
  18. // @connect metacritic.com
  19. // @connect php-cuzi.herokuapp.com
  20. // @include https://*.bandcamp.com/*
  21. // @include https://play.google.com/store/music/album/*
  22. // @include https://play.google.com/store/movies/details/*
  23. // @include https://music.amazon.com/*
  24. // @include https://www.amazon.ca/*
  25. // @include https://www.amazon.co.jp/*
  26. // @include https://www.amazon.co.uk/*
  27. // @include https://smile.amazon.co.uk/*
  28. // @include https://www.amazon.com.au/*
  29. // @include https://www.amazon.com.mx/*
  30. // @include https://www.amazon.com/*
  31. // @include https://smile.amazon.com/*
  32. // @include https://www.amazon.de/*
  33. // @include https://smile.amazon.de/*
  34. // @include https://www.amazon.es/*
  35. // @include https://www.amazon.fr/*
  36. // @include https://www.amazon.in/*
  37. // @include https://www.amazon.it/*
  38. // @include https://www.imdb.com/title/*
  39. // @include https://store.steampowered.com/app/*
  40. // @include https://www.gamespot.com/*
  41. // @include https://www.serienjunkies.de/*
  42. // @include https://www.rottentomatoes.com/m/*
  43. // @include https://rottentomatoes.com/m/*
  44. // @include https://www.rottentomatoes.com/tv/*
  45. // @include https://rottentomatoes.com/tv/*
  46. // @include https://www.rottentomatoes.com/tv/*/s*/
  47. // @include https://rottentomatoes.com/tv/*/s*/
  48. // @include https://www.boxofficemojo.com/movies/*
  49. // @include https://www.boxofficemojo.com/release/*
  50. // @include https://www.allmovie.com/movie/*
  51. // @include https://en.wikipedia.org/*
  52. // @include https://www.fandango.com/*
  53. // @include https://www.flixster.com/movie/*
  54. // @include https://www.themoviedb.org/movie/*
  55. // @include https://www.themoviedb.org/tv/*
  56. // @include https://letterboxd.com/film/*
  57. // @exclude https://letterboxd.com/film/*/image*
  58. // @include https://www.tvmaze.com/shows/*
  59. // @include https://www.tvguide.com/tvshows/*
  60. // @include https://followshows.com/show/*
  61. // @include https://thetvdb.com/series/*
  62. // @include https://thetvdb.com/movies/*
  63. // @include https://consequenceofsound.net/*
  64. // @include https://consequence.net/*
  65. // @include https://pitchfork.com/*
  66. // @include https://www.last.fm/*
  67. // @include https://tvnfo.com/s/*
  68. // @include https://rateyourmusic.com/release/album/*
  69. // @include https://open.spotify.com/*
  70. // @include https://play.spotify.com/album/*
  71. // @include https://www.nme.com/reviews/*
  72. // @include https://www.albumoftheyear.org/album/*
  73. // @include https://itunes.apple.com/*/movie/*
  74. // @include https://itunes.apple.com/*/album/*
  75. // @include https://music.apple.com/*/album/*
  76. // @include https://itunes.apple.com/*/tv-season/*
  77. // @include https://epguides.com/*
  78. // @include https://www.epguides.com/*
  79. // @include https://sharetv.com/shows/*
  80. // @include https://www.netflix.com/*
  81. // @include https://www.cc.com/*
  82. // @include https://www.tvhoard.com/*
  83. // @include https://www.amc.com/*
  84. // @include https://www.amcplus.com/*
  85. // @include https://rlsbb.ru/*/
  86. // @include https://newalbumreleases.net/*
  87. // @include https://www.sho.com/*
  88. // @include https://www.epicgames.com/store/*
  89. // @include https://www.gog.com/*
  90. // @include https://www.allmusic.com/album/*
  91. // @include https://store.epicgames.com/*
  92. // ==/UserScript==
  93.  
  94. /* globals alert, confirm, GM, DOMParser, $, Image, unsafeWindow, parent, Blob */
  95.  
  96. const baseURL = 'https://www.metacritic.com/'
  97.  
  98. const baseURLmusic = 'https://www.metacritic.com/music/'
  99. const baseURLmovie = 'https://www.metacritic.com/movie/'
  100. const baseURLpcgame = 'https://www.metacritic.com/game/pc/'
  101. const baseURLps4 = 'https://www.metacritic.com/game/playstation-4/'
  102. const baseURLxone = 'https://www.metacritic.com/game/xbox-one/'
  103. const baseURLtv = 'https://www.metacritic.com/tv/'
  104.  
  105. const baseURLsearch = 'https://www.metacritic.com/search/{type}/{query}/results'
  106. const baseURLautosearch = 'https://www.metacritic.com/autosearch'
  107.  
  108. const baseURLdatabase = 'https://php-cuzi.herokuapp.com/r.php'
  109. const baseURLwhitelist = 'https://php-cuzi.herokuapp.com/whitelist.php'
  110. const baseURLblacklist = 'https://php-cuzi.herokuapp.com/blacklist.php'
  111.  
  112. const TEMPORARY_BLACKLIST_TIMEOUT = 5 * 60
  113.  
  114. // http://www.designcouch.com/home/why/2013/05/23/dead-simple-pure-css-loading-spinner/
  115. const CSS = '#mcdiv123 .grespinner{height:16px;width:16px;margin:0 auto;position:relative;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%}@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%}'
  116.  
  117. let myDOMParser = null
  118. function domParser () {
  119. if (myDOMParser === null) {
  120. myDOMParser = new DOMParser()
  121. }
  122. return myDOMParser
  123. }
  124.  
  125. async function versionUpdate () {
  126. const version = parseInt(await GM.getValue('version', 0))
  127. if (version <= 51) {
  128. // Reset database
  129. await GM.setValue('map', '{}')
  130. await GM.setValue('black', '[]')
  131. await GM.setValue('hovercache', '{}')
  132. await GM.setValue('requestcache', '{}')
  133. await GM.setValue('searchcache', '{}')
  134. await GM.setValue('autosearchcache', '{}')
  135. await GM.setValue('temporaryblack', '{}')
  136. }
  137. if (version < 55) {
  138. await GM.setValue('version', 55)
  139. }
  140. }
  141.  
  142. async function acceptGDPR (showDialog) {
  143. if (showDialog === true) {
  144. await GM.setValue('gdpr', null)
  145. return acceptGDPR()
  146. }
  147. return new Promise(function (resolve) {
  148. GM.getValue('gdpr', null).then(function (value) {
  149. if (value === true) {
  150. return resolve(true)
  151. }
  152. if (value === false) {
  153. return resolve(false)
  154. }
  155. const html = '<h1>Privacy Policy for &quot;Show Metacritic.com ratings&quot;</h1><h2>General Data Protection Regulation (GDPR)</h2><p>We are a Data Controller of your information.</p> <p>&quot;Show Metacritic.com ratings&quot; legal basis for collecting and using the personal information described in this Privacy Policy depends on the Personal Information we collect and the specific context in which we collect the information:</p><ul> <li>&quot;Show Metacritic.com ratings&quot; needs to perform a contract with you</li> <li>You have given &quot;Show Metacritic.com ratings&quot; permission to do so</li> <li>Processing your personal information is in &quot;Show Metacritic.com ratings&quot; legitimate interests</li> <li>&quot;Show Metacritic.com ratings&quot; needs to comply with the law</li></ul> <p>&quot;Show Metacritic.com ratings&quot; will retain your personal information only for as long as is necessary for the purposes set out in this Privacy Policy. We will retain and use your information to the extent necessary to comply with our legal obligations, resolve disputes, and enforce our policies.</p> <p>If you are a resident of the European Economic Area (EEA), you have certain data protection rights. If you wish to be informed what Personal Information we hold about you and if you want it to be removed from our systems, please contact us. Our Privacy Policy was generated with the help of <a href="https://www.gdprprivacypolicy.net/">GDPR Privacy Policy Generator</a> and the <a href="https://www.app-privacy-policy.com">App Privacy Policy Generator</a>.</p><p>In certain circumstances, you have the following data protection rights:</p><ul> <li>The right to access, update or to delete the information we have on you.</li> <li>The right of rectification.</li> <li>The right to object.</li> <li>The right of restriction.</li> <li>The right to data portability</li> <li>The right to withdraw consent</li></ul><h2>Log Files</h2><p>&quot;Show Metacritic.com ratings&quot; follows a standard procedure of using log files. These files log visitors when they visit websites. All hosting companies do this and a part of hosting services\' analytics. The information collected by log files include internet protocol (IP) addresses, browser type, Internet Service Provider (ISP), date and time stamp, referring/exit pages, and possibly the number of clicks. These are not linked to any information that is personally identifiable. The purpose of the information is for analyzing trends, administering the site, tracking users\' movement on the website, and gathering demographic information.</p><h2>Privacy Policies</h2><P>You may consult this list to find the Privacy Policy for each of the advertising partners of &quot;Show Metacritic.com ratings&quot;.</p><p>Third-party ad servers or ad networks uses technologies like cookies, JavaScript, or Web Beacons that are used in their respective advertisements and links that appear on &quot;Show Metacritic.com ratings&quot;, which are sent directly to users\' browser. They automatically receive your IP address when this occurs. These technologies are used to measure the effectiveness of their advertising campaigns and/or to personalize the advertising content that you see on websites that you visit.</p><p>Note that &quot;Show Metacritic.com ratings&quot; has no access to or control over these cookies that are used by third-party advertisers.</p><h2>Third Party Privacy Policies</h2><p>&quot;Show Metacritic.com ratings&quot;\'s Privacy Policy does not apply to other advertisers or websites. Thus, we are advising you to consult the respective Privacy Policies of these third-party ad servers for more detailed information. It may include their practices and instructions about how to opt-out of certain options.List of these Privacy Policies and their links: <ul> <li>Heroku: <a href="https://www.salesforce.com/company/privacy/">https://www.salesforce.com/company/privacy/</a></li> <li>www.metacritic.com: <a href="https://privacy.cbs/">https://privacy.cbs/</a></li></ul></p><p>You can choose to disable cookies through your individual browser options.</p><h2>Children\'s Information</h2><p>Another part of our priority is adding protection for children while using the internet. We encourage parents and guardians to observe, participate in, and/or monitor and guide their online activity.</p><p>&quot;Show Metacritic.com ratings&quot; does not knowingly collect any Personal Identifiable Information from children under the age of 13. If you think that your child provided this kind of information on our website, we strongly encourage you to contact us immediately and we will do our best efforts to promptly remove such information from our records.</p><h2>Online Privacy Policy Only</h2><p>Our Privacy Policy created at GDPRPrivacyPolicy.net) applies only to our online activities and is valid for users of our program with regards to the information that they shared and/or collect in &quot;Show Metacritic.com ratings&quot;. This policy is not applicable to any information collected offline or via channels other than this program. <a href="https://gdprprivacypolicy.net">Our GDPR Privacy Policy</a> was generated from the GDPR Privacy Policy Generator.</p><h2>Contact</h2><p>Contact us via github <a href="https://github.com/cvzi/Metacritic-userscript">https://github.com/cvzi/Metacritic-userscript</a> or email cuzi@openmail.cc</p><h2>Consent</h2><p>By using our program ("userscript"), you hereby consent to our Privacy Policy and agree to its terms.</p>'
  156. const div = document.body.appendChild(document.createElement('div'))
  157. div.innerHTML = html
  158. div.style = 'z-index:9999;position:absolute;min-height:100%;top:0px; left:0px; right:0px; padding:10px; background:white; color:black; font-family:serif; font-size:16px'
  159. div.appendChild(document.createElement('br'))
  160. const acceptButton = div.appendChild(document.createElement('button'))
  161. acceptButton.setAttribute('style', 'color:black;background:#e5e4e4;border:2px #bbb outset;margin:5px;padding:2px 10px;font-size:16px;font-family:sans-serif;cursor:pointer')
  162. acceptButton.appendChild(document.createTextNode('Accept'))
  163. acceptButton.addEventListener('click', function () {
  164. div.remove()
  165. resolve(true)
  166. GM.setValue('gdpr', true)
  167. })
  168. const declineButton = div.appendChild(document.createElement('button'))
  169. declineButton.setAttribute('style', 'color:black;background:#e5e4e4;border:2px #bbb outset;margin:5px;padding:2px 10px;font-size:16px;font-family:sans-serif;cursor:pointer')
  170. declineButton.appendChild(document.createTextNode('Decline'))
  171. declineButton.addEventListener('click', function () {
  172. alert('You may uninstall the userscript now.')
  173. div.remove()
  174. resolve(false)
  175. GM.setValue('gdpr', false)
  176. })
  177. const space = div.appendChild(document.createElement('div'))
  178. space.style = 'height:2000px;'
  179. div.scrollIntoView()
  180. window.setTimeout(function () {
  181. alert('ShowMetacriticRatings:\n\nWhen you use this script, data will be sent to our database and to metacritic.com. This data includes the url of the website that you are browsing, the metacritic page url, your IP adress, browser configuration and language preferences. We only store the url of the website and the metacritic url and no personal information. Log files are temporarily retained and contain your IP address. We have no control over which data is stored by metacritic.com and our hoster heroku.com, see their respective privacy policies for more information (see "Third Party Privacy Policies").\n\nPlease read and accept our privacy policy now or uninstall this userscript.')
  182. }, 20)
  183. })
  184. })
  185. }
  186.  
  187. function delay (ms) {
  188. return new Promise(function (resolve) {
  189. window.setTimeout(() => resolve(), ms)
  190. })
  191. }
  192.  
  193. function getHostname (url) {
  194. const a = document.createElement('a')
  195. a.href = url
  196. return a.hostname
  197. }
  198. function absoluteMetaURL (url) {
  199. if (url.startsWith('https://')) {
  200. return url
  201. }
  202. if (url.startsWith('http://')) {
  203. return 'https' + url.substr(4)
  204. }
  205. if (url.startsWith('//')) {
  206. return baseURL + url.substr(2)
  207. }
  208. if (url.startsWith('/')) {
  209. return baseURL + url.substr(1)
  210. }
  211. return baseURL + url
  212. }
  213.  
  214. const parseLDJSONCache = {}
  215. function parseLDJSON (keys, condition) {
  216. if (document.querySelector('script[type="application/ld+json"]')) {
  217. const data = []
  218. const scripts = document.querySelectorAll('script[type="application/ld+json"]')
  219. for (let i = 0; i < scripts.length; i++) {
  220. let jsonld
  221. if (scripts[i].innerText in parseLDJSONCache) {
  222. jsonld = parseLDJSONCache[scripts[i].innerText]
  223. } else {
  224. try {
  225. jsonld = JSON.parse(scripts[i].innerText)
  226. parseLDJSONCache[scripts[i].innerText] = jsonld
  227. } catch (e) {
  228. parseLDJSONCache[scripts[i].innerText] = null
  229. continue
  230. }
  231. }
  232. if (jsonld) {
  233. if (Array.isArray(jsonld)) {
  234. data.push(...jsonld)
  235. } else {
  236. data.push(jsonld)
  237. }
  238. }
  239. }
  240. for (let i = 0; i < data.length; i++) {
  241. try {
  242. if (data[i] && data[i] && (typeof condition !== 'function' || condition(data[i]))) {
  243. if (Array.isArray(keys)) {
  244. const r = []
  245. for (let j = 0; j < keys.length; j++) {
  246. r.push(data[i][keys[j]])
  247. }
  248. return r
  249. } else if (keys) {
  250. return data[i][keys]
  251. } else if (typeof condition === 'function') {
  252. return data[i] // Return whole object
  253. }
  254. }
  255. } catch (e) {
  256. continue
  257. }
  258. }
  259. return data
  260. }
  261. return null
  262. }
  263.  
  264. function name2metacritic (s) {
  265. const mc = s.normalize('NFKD').replace(/\//g, '').replace(/[\u0300-\u036F]/g, '').replace(/&/g, 'and').replace(/\W+/g, ' ').toLowerCase().trim().replace(/\W+/g, '-')
  266. if (!mc) {
  267. throw new Error("name2metacritic converted '" + s + "' to empty string")
  268. }
  269. return mc
  270. }
  271. function minutesSince (time) {
  272. const seconds = ((new Date()).getTime() - time.getTime()) / 1000
  273. return seconds > 60 ? parseInt(seconds / 60) + ' min ago' : 'now'
  274. }
  275. function randomStringId () {
  276. const id10 = () => Math.floor((1 + Math.random()) * 0x10000000000).toString(16).substring(1)
  277. return id10() + id10() + id10() + id10() + id10() + id10()
  278. }
  279. function fixMetacriticURLs (html) {
  280. return html.replace(/<a /g, '<a target="_blank" ').replace(/href="\//g, 'href="' + baseURL).replace(/src="\//g, 'src="' + baseURL)
  281. }
  282. function searchType2metacritic (type) {
  283. return ({
  284. movie: 'movie',
  285. pcgame: 'game',
  286. xonegame: 'game',
  287. ps4game: 'game',
  288. music: 'album',
  289. tv: 'tv'
  290. })[type]
  291. }
  292. function metacritic2searchType (type) {
  293. return ({
  294. Album: 'music',
  295. TV: 'tv',
  296. Movie: 'movie',
  297. 'PC Game': 'pcgame',
  298. 'PS4 Game': 'ps4game',
  299. 'XONE Game': 'onegame',
  300. 'WIIU Game': 'xxxxx',
  301. '3DS Game': 'xxxx'
  302. })[type]
  303. }
  304.  
  305. function replaceBrackets (str) {
  306. str = str.replace(/\([^\(]*\)/g, '')
  307. str = str.replace(/\[[^\]]*\]/g, '')
  308. return str.trim()
  309. }
  310. function removeSymbols (str) {
  311. str = str.replace(/[^\s0-9A-Za-zÀ-ÖØ-öø-ÿ]*/gi, '').trim()
  312. return str.trim()
  313. }
  314. const dashRegExp = new RegExp('[-\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D]')
  315. function removeAnythingAfterDash (str) {
  316. str = str.split(dashRegExp)[0]
  317. return str.trim()
  318. }
  319.  
  320. function broadenSearch (data, step, type) {
  321. if (type === 'pcgame') {
  322. if (step > 0) {
  323. data[0] = replaceBrackets(data[0])
  324. } else if (step > 1) {
  325. data[0] = removeSymbols(data[0])
  326. } else if (step > 2) {
  327. data[0] = removeAnythingAfterDash(data[0])
  328. }
  329. }
  330. return data
  331. }
  332.  
  333. function balloonAlert (message, timeout, title, css, click) {
  334. let header
  335. if (title) {
  336. header = '<div style="background:rgb(220,230,150); padding: 2px 12px;">' + title + '</div>'
  337. } else if (title === false) {
  338. header = ''
  339. } else {
  340. header = '<div style="background:rgb(220,230,150); padding: 2px 12px;">Userscript alert</div>'
  341. }
  342. const div = $('<div>' + header + '<div style="padding:5px">' + message.split('\n').join('<br>') + '</div></div>')
  343. div.css({
  344. position: 'fixed',
  345. top: 10,
  346. left: 10,
  347. maxWidth: 200,
  348. zIndex: '2147483601',
  349. background: 'rgb(240,240,240)',
  350. border: '2px solid yellow',
  351. borderRadius: '6px',
  352. boxShadow: '0 0 3px 3px rgba(100, 100, 100, 0.2)',
  353. fontFamily: 'sans-serif',
  354. color: 'black'
  355. })
  356. if (css) {
  357. div.css(css)
  358. }
  359. div.appendTo(document.body)
  360.  
  361. if (click) {
  362. div.click(function (ev) {
  363. $(this).hide(500)
  364. click.call(this, ev)
  365. })
  366. }
  367.  
  368. if (!click) {
  369. const close = $('<div title="Close" style="cursor:pointer; position:absolute; top:0px; right:3px;">&#10062;</div>').appendTo(div)
  370. close.click(function () {
  371. $(this.parentNode).hide(1000)
  372. })
  373. }
  374.  
  375. if (timeout && timeout > 0) {
  376. window.setTimeout(function () {
  377. div.hide(3000)
  378. }, timeout)
  379. }
  380. return div
  381. }
  382.  
  383. function filterUniversalUrl (url) {
  384. try {
  385. url = url.match(/http.+/)[0]
  386. } catch (e) { }
  387.  
  388. try {
  389. url = url.replace(/https?:\/\/(www.)?/, '')
  390. } catch (e) { }
  391.  
  392. if (url.indexOf('#') !== -1) {
  393. url = url.split('#')[0]
  394. }
  395.  
  396. if (url.startsWith('imdb.com/') && url.match(/(imdb\.com\/\w+\/\w+\/)/)) {
  397. // Remove movie subpage from imdb url
  398. return url.match(/(imdb\.com\/\w+\/\w+\/)/)[1]
  399. } else if (url.startsWith('boxofficemojo.com/') && url.indexOf('id=') !== -1) {
  400. // Keep the important id= on
  401. try {
  402. const parts = url.split('?')
  403. const page = parts[0] + '?'
  404. const idparam = parts[1].match(/(id=.+?)(\.|&)/)[1]
  405. return page + idparam
  406. } catch (e) {
  407. return url
  408. }
  409. } else {
  410. // Default: Remove parameters
  411. return url.split('?')[0].split('&')[0]
  412. }
  413. }
  414.  
  415. async function addToMap (url, metaurl) {
  416. const data = JSON.parse(await GM.getValue('map', '{}'))
  417.  
  418. url = filterUniversalUrl(url)
  419. metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//, '')
  420.  
  421. data[url] = metaurl
  422.  
  423. await GM.setValue('map', JSON.stringify(data));
  424.  
  425. (new Image()).src = baseURLwhitelist + '?docurl=' + encodeURIComponent(url) + '&metaurl=' + encodeURIComponent(metaurl) + '&ref=' + encodeURIComponent(randomStringId())
  426. return [url, metaurl]
  427. }
  428.  
  429. async function removeFromMap (url) {
  430. const data = JSON.parse(await GM.getValue('map', '{}'))
  431.  
  432. url = filterUniversalUrl(url)
  433. if (url in data) {
  434. delete data[url]
  435. await GM.setValue('map', JSON.stringify(data))
  436. }
  437. }
  438.  
  439. async function addToTemporaryBlacklist (metaurl) {
  440. const data = JSON.parse(await GM.getValue('temporaryblack', '{}'))
  441.  
  442. metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//, '')
  443. metaurl = metaurl.replace(/\/\//g, '/').replace(/\/\//g, '/')
  444. metaurl = metaurl.replace(/^\/+/, '')
  445.  
  446. data[metaurl] = (new Date()).toJSON()
  447.  
  448. // Remove old entries
  449. const now = (new Date()).getTime()
  450. const timeout = TEMPORARY_BLACKLIST_TIMEOUT * 1000
  451. for (const prop in data) {
  452. if (now - (new Date(data[prop].time)).getTime() > timeout) {
  453. delete data[prop]
  454. }
  455. }
  456.  
  457. await GM.setValue('temporaryblack', JSON.stringify(data))
  458.  
  459. return true
  460. }
  461.  
  462. async function isTemporaryBlacklisted (metaurl) {
  463. const data = JSON.parse(await GM.getValue('temporaryblack', '{}'))
  464.  
  465. metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//, '')
  466. metaurl = metaurl.replace(/\/\//g, '/').replace(/\/\//g, '/')
  467. metaurl = metaurl.replace(/^\/+/, '')
  468.  
  469. if (metaurl in data) {
  470. const now = (new Date()).getTime()
  471. const timeout = TEMPORARY_BLACKLIST_TIMEOUT * 1000
  472. if (now - (new Date(data[metaurl])).getTime() < timeout) {
  473. return true
  474. }
  475. }
  476. return false
  477. }
  478.  
  479. async function addToBlacklist (url, metaurl) {
  480. const data = JSON.parse(await GM.getValue('black', '[]'))
  481.  
  482. url = filterUniversalUrl(url)
  483. metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//, '')
  484.  
  485. data.push([url, metaurl])
  486.  
  487. await GM.setValue('black', JSON.stringify(data));
  488.  
  489. (new Image()).src = baseURLblacklist + '?docurl=' + encodeURIComponent(url) + '&metaurl=' + encodeURIComponent(metaurl) + '&ref=' + encodeURIComponent(randomStringId())
  490. return [url, metaurl]
  491. }
  492.  
  493. async function removeFromBlacklist (docurl, metaurl) {
  494. docurl = filterUniversalUrl(docurl)
  495. docurl = docurl.replace(/https?:\/\/(www.)?/, '')
  496.  
  497. metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//, '')
  498. metaurl = metaurl.replace(/\/\//g, '/').replace(/\/\//g, '/') // remove double slash
  499. metaurl = metaurl.replace(/^\/+/, '') // remove starting slash
  500.  
  501. const data = JSON.parse(await GM.getValue('black', '[]')) // [ [docurl0, metaurl0] , [docurl1, metaurl1] , ... ]
  502. const found = []
  503. for (let i = 0; i < data.length; i++) {
  504. if (data[i][0] === docurl && data[i][1] === metaurl) {
  505. found.push(i)
  506. }
  507. }
  508. for (let i = found.length - 1; i >= 0; i--) {
  509. data.pop(i)
  510. }
  511.  
  512. await GM.setValue('black', JSON.stringify(data))
  513. }
  514.  
  515. async function isBlacklistedUrl (docurl, metaurl) {
  516. docurl = filterUniversalUrl(docurl)
  517. docurl = docurl.replace(/https?:\/\/(www.)?/, '')
  518.  
  519. metaurl = metaurl.replace(/^https?:\/\/(www.)?metacritic\.com\//, '')
  520. metaurl = metaurl.replace(/\/\//g, '/').replace(/\/\//g, '/') // remove double slash
  521. metaurl = metaurl.replace(/^\/+/, '') // remove starting slash
  522.  
  523. const data = JSON.parse(await GM.getValue('black', '[]')) // [ [docurl0, metaurl0] , [docurl1, metaurl1] , ... ]
  524. for (let i = 0; i < data.length; i++) {
  525. if (data[i][0] === docurl && data[i][1] === metaurl) {
  526. return true
  527. }
  528. }
  529. return false
  530. }
  531.  
  532. let listenForHotkeysActive = false
  533. function listenForHotkeys (code, cb) {
  534. // Call cb() as soon as the code sequence was typed
  535. if (listenForHotkeysActive) {
  536. return
  537. }
  538. listenForHotkeysActive = true
  539. let i = 0
  540. $(document).bind('keydown.listenForHotkeys', function (ev) {
  541. if (document.activeElement === document.body) {
  542. if (ev.key !== code[i]) {
  543. i = 0
  544. } else {
  545. i++
  546. if (i === code.length) {
  547. ev.preventDefault()
  548. $(document).unbind('keydown.listenForHotkeys')
  549. cb()
  550. }
  551. }
  552. }
  553. })
  554. }
  555.  
  556. function waitForHotkeysMETA () {
  557. listenForHotkeys('meta', (ev) => openSearchBox())
  558. }
  559.  
  560. function asyncRequest (data) {
  561. return new Promise(async function (resolve, reject) {
  562. const cachedValue = await isInRequestCache(data)
  563. if (cachedValue) {
  564. return resolve(cachedValue)
  565. }
  566. const defaultHeaders = {
  567. Referer: data.url,
  568. // Host: getHostname(data.url),
  569. 'User-Agent': navigator.userAgent
  570. }
  571. const defaultData = {
  572. method: 'GET',
  573. onload: function (response) {
  574. storeInRequestCache(data, response)
  575. resolve(response)
  576. },
  577. onerror: (response) => reject(response)
  578. }
  579. if ('headers' in data) {
  580. data.headers = Object.assign(defaultHeaders, data.headers)
  581. } else {
  582. data.headers = defaultHeaders
  583. }
  584.  
  585. data = Object.assign(defaultData, data)
  586. GM.xmlHttpRequest(data)
  587. })
  588. }
  589.  
  590. async function handleJSONredirect (response) {
  591. let blacklistedredirect = false
  592. const j = JSON.parse(response.responseText)
  593.  
  594. // Blacklist items from database received?
  595. if ('blacklist' in j && j.blacklist && j.blacklist.length) {
  596. // Save new blacklist items
  597. const data = JSON.parse(await GM.getValue('black', '[]'))
  598. for (let i = 0; i < j.blacklist.length; i++) {
  599. const saveDocurl = j.blacklist[i].docurl
  600. const saveMetaurl = j.blacklist[i].metaurl
  601.  
  602. data.push([saveDocurl, saveMetaurl])
  603. if (j.jsonRedirect === '/' + saveMetaurl) {
  604. // Redirect is blacklisted!
  605. blacklistedredirect = true
  606. }
  607. }
  608. await GM.setValue('black', JSON.stringify(data))
  609. }
  610. if (blacklistedredirect) {
  611. // Redirect was blacklisted, show nothing
  612. console.debug('ShowMetacriticRatings: Redirect was blacklisted -> show nothing')
  613. return null
  614. } else {
  615. // Load redirect
  616. current.metaurl = absoluteMetaURL(j.jsonRedirect)
  617. response = await asyncRequest({
  618. method: 'POST',
  619. url: current.metaurl,
  620. data: 'hoverinfo=1',
  621. headers: {
  622. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  623. 'X-Requested-With': 'XMLHttpRequest'
  624. }
  625. }).catch(function (response) {
  626. console.error('ShowMetacriticRatings: Error 01')
  627. })
  628. return response
  629. }
  630. }
  631.  
  632. function extractHoverFromFullPage (response) {
  633. let html = 'ShowMetacriticRatings:<br>Error occured in extractHoverFromFullPage()'
  634. try {
  635. // Try parsing HTML
  636. const doc = domParser().parseFromString(response.responseText, 'text/html')
  637. doc.querySelector('.product_page_title h1')
  638. doc.querySelector('.summary_img')
  639. doc.querySelectorAll('.details_section')
  640. doc.querySelectorAll('#nav_to_metascore .distribution')
  641.  
  642. let pageUrl = ''
  643. let imgSrc = ''
  644. let imgAlt = ''
  645. let title = ''
  646. let publisher = ''
  647. let releaseDate = ''
  648. let starring = ''
  649. let criticsScore = ''
  650. let criticsClass = ''
  651. let criticsNumber = ''
  652. let criticsCharts = ''
  653. let userScore = ''
  654. let userClass = ''
  655. let userNumber = ''
  656. let userCharts = ''
  657.  
  658. pageUrl = response.finalUrl + (response.finalUrl.endsWith('/') ? '' : '/')
  659. imgSrc = doc.querySelector('.summary_img').src
  660. imgAlt = doc.querySelector('.summary_img').alt
  661. title = doc.querySelector('.product_page_title h1').textContent
  662. if (doc.querySelector('.details_section .distributor a')) { publisher = doc.querySelector('.details_section .distributor a').textContent }
  663.  
  664. if (doc.querySelector('.details_section .release_date span:nth-child(2)')) {
  665. const date = doc.querySelector('.details_section .release_date span:nth-child(2)').textContent
  666. releaseDate = `
  667. <div class="summary_detail release_data">
  668. <span class="label">Release Date:</span>
  669. <span class="data">${date}</span>
  670. </div>`
  671. }
  672.  
  673. if (doc.querySelector('.details_section.summary_cast span:nth-child(2)')) {
  674. const stars = doc.querySelector('.details_section.summary_cast span:nth-child(2)').innerHTML
  675. starring = `
  676. <div>
  677. <div class="summary_detail product_credits">
  678. <span class="label">Starring:</span>
  679. <span class="data">
  680. ${stars}
  681. </span>
  682. </div>
  683. </div>`
  684. }
  685.  
  686. criticsClass = 'metascore_w medium tbd'
  687. criticsScore = 'tbd'
  688. userClass = 'metascore_w medium user tbd'
  689. userScore = 'tbd'
  690.  
  691. if (doc.querySelector('.score_details .based_on')) {
  692. criticsNumber = doc.querySelector('.score_details .based_on').textContent.match(/\d+/)
  693. } else {
  694. criticsNumber = 'By'
  695. }
  696. if (doc.querySelector('.user_score_summary .based_on')) {
  697. userNumber = doc.querySelector('.user_score_summary .based_on').textContent.match(/\d+/)
  698. } else {
  699. userNumber = 'User'
  700. }
  701.  
  702. // Remove text from distribution charts:
  703. let label = doc.querySelector('#nav_to_metascore .charts .label.fl')
  704. while (label) {
  705. label.parentNode.title = label.textContent.trim() + ' ' + label.parentNode.querySelector('.count').textContent.trim()
  706. label.remove()
  707. label = doc.querySelector('#nav_to_metascore .charts .label.fl')
  708. }
  709. const scores = doc.querySelectorAll('#nav_to_metascore .distribution .metascore_w')
  710. if (scores.length === 2) {
  711. criticsScore = scores[0].innerText
  712. criticsClass = scores[0].className.replace('larger', 'medium')
  713. scores[0].parentNode.parentNode.querySelector('.charts').style.width = '40px'
  714. criticsCharts = '<td class="meta">' + scores[0].parentNode.parentNode.querySelector('.charts').outerHTML + '</td>'
  715. userScore = scores[1].innerText
  716. userClass = scores[1].className.replace('larger', 'medium')
  717. scores[1].parentNode.parentNode.querySelector('.charts').style.width = '40px'
  718. userCharts = '<td class="usr">' + scores[1].parentNode.parentNode.querySelector('.charts').outerHTML + '</td>'
  719. } else if (scores.length === 1) {
  720. if (scores[0].className.indexOf('user') === -1) {
  721. criticsScore = scores[0].innerText
  722. criticsClass = scores[0].className.replace('larger', 'medium')
  723. scores[0].parentNode.parentNode.querySelector('.charts').style.width = '40px'
  724. criticsCharts = '<td class="meta">' + scores[0].parentNode.parentNode.querySelector('.charts').outerHTML + '</td>'
  725. } else {
  726. userScore = scores[0].innerText
  727. userClass = scores[0].className.replace('larger', 'medium')
  728. scores[0].parentNode.parentNode.querySelector('.charts').style.width = '40px'
  729. userCharts = '<td class="usr">' + scores[0].parentNode.parentNode.querySelector('.charts').outerHTML + '</td>'
  730. }
  731. }
  732.  
  733. html = `
  734. <div class="hoverinfo">
  735. <div class="hover_left">
  736. <div class="product_image_wrapper">
  737. <a target="_blank" href="${pageUrl}">
  738. <img class="product_image large_image" src="${imgSrc}" alt="${imgAlt}" />
  739. </a>
  740. </div>
  741. </div>
  742. <div class="hover_right">
  743. <h2 class="product_title">
  744. <a target="_blank" href="${pageUrl}">${title}</a>
  745. </h2>
  746. <div>
  747. <div class="summary_detail publisher">
  748. <span class="data">${publisher}</span>
  749. <span>&nbsp;|&nbsp;&nbsp;</span>
  750. </div>
  751. ${releaseDate}
  752. <div class="clr"></div>
  753. </div>
  754. ${starring}
  755. <div class="hr">
  756. &nbsp;
  757. </div>
  758.  
  759. <table class="hover_scores ">
  760. <tr>
  761. <td class="meta num">
  762. <a target="_blank" class="metascore_anchor" href="${pageUrl}#nav_to_metascore">
  763. <span class="${criticsClass}">${criticsScore}</span>
  764. </a>
  765. </td>
  766. <td class="meta txt">
  767. <div class="metascore_label">Metascore</div>
  768. <div class="metascore_review_count">
  769. <a target="_blank" href="${pageUrl}#nav_to_metascore">
  770. <span>${criticsNumber}</span> critics
  771. </a>
  772. </div>
  773. </td>
  774. ${criticsCharts}
  775. <td class="usr num">
  776.  
  777. <a target="_blank" class="metascore_anchor" href="${pageUrl}#nav_to_metascore">
  778. <span class="${userClass}">${userScore}</span>
  779. </a>
  780.  
  781. </td>
  782. <td class="usr txt">
  783. <div class="userscore_label">User Score</div>
  784. <div class="userscore_review_count">
  785. <a target="_blank" href="${pageUrl}#nav_to_metascore">
  786. <span>${userNumber}</span> Ratings
  787. </a>
  788. </div>
  789. </td>
  790. ${userCharts}
  791. </tr>
  792. </table>
  793.  
  794. </div>
  795.  
  796. <div class="clr"></div>
  797. </div>
  798. `
  799. } catch (e) {
  800. console.warn('ShowMetacriticRatings: Error parsing HTML: ' + e)
  801.  
  802. // fallback to cutting out the relevant parts
  803.  
  804. let parts = response.responseText.split('class="score_details')
  805. const textPart = '<div class="' + parts[1].split('</div>')[0] + '</div>'
  806.  
  807. let titleText = '<div class="product_page_title' + response.responseText.split('class="product_page_title')[1].split('</div>')[0]
  808. titleText = titleText.split('<h1>').join('<h1 style="padding:0px; margin:2px">') + '</div>'
  809.  
  810. parts = response.responseText.split('id="nav_to_metascore"')
  811. let metaScorePart = '<div ' + parts[1].split('<div class="subsection_title"')[0] + '</div></div>'
  812.  
  813. metaScorePart = metaScorePart.split('href="">').join('href="' + response.finalUrl + '">')
  814. metaScorePart = metaScorePart.split('section_title bold">').join('section_title bold">' + titleText)
  815.  
  816. html = metaScorePart.split('<div class="distribution">').join(textPart + '<div class="distribution">')
  817.  
  818. if (html.indexOf('products_module') !== -1) {
  819. // Critic reviews are not available for this Series yet -> Cut the preview for other series
  820. html = html.split('products_module')[0] + '"></div>'
  821. }
  822.  
  823. if (html.length > 5000) {
  824. // Probably something went wrong, let's cut the response to prevent too long content
  825. console.warn('ShowMetacriticRatings: Cutting response to 5000 chars')
  826. html = html.substr(0, 5000)
  827. }
  828. }
  829. return html
  830. }
  831.  
  832. async function storeInRequestCache (requestData, response) {
  833. if ('onload' in requestData) {
  834. delete requestData.onload
  835. }
  836. if ('onerror' in requestData) {
  837. delete requestData.onerror
  838. }
  839. const newkey = JSON.stringify(requestData)
  840. const cache = JSON.parse(await GM.getValue('requestcache', '{}'))
  841. const now = (new Date()).getTime()
  842. const timeout = 15 * 60 * 1000
  843. for (const prop in cache) {
  844. // Delete cached values, that are older than 15 minutes
  845. if (now - (new Date(cache[prop].time)).getTime() > timeout) {
  846. delete cache[prop]
  847. }
  848. }
  849.  
  850. const newobj = {}
  851. for (const key in response) {
  852. newobj[key] = response[key]
  853. }
  854. newobj.responseText = '' + response.responseText
  855. newobj.cached = true
  856. if (!('time' in newobj)) {
  857. newobj.time = (new Date()).toJSON()
  858. }
  859.  
  860. cache[newkey] = newobj
  861.  
  862. await GM.setValue('requestcache', JSON.stringify(cache))
  863. }
  864.  
  865. async function isInRequestCache (requestData) {
  866. if ('onload' in requestData) {
  867. delete requestData.onload
  868. }
  869. if ('onerror' in requestData) {
  870. delete requestData.onerror
  871. }
  872. const key = JSON.stringify(requestData)
  873.  
  874. const cache = JSON.parse(await GM.getValue('requestcache', '{}'))
  875. const now = (new Date()).getTime()
  876. const timeout = 15 * 60 * 1000
  877. for (const prop in cache) {
  878. // Delete cached values, that are older than 15 minutes
  879. if (now - (new Date(cache[prop].time)).getTime() > timeout) {
  880. delete cache[prop]
  881. }
  882. }
  883.  
  884. if (key in cache) {
  885. return cache[key]
  886. } else {
  887. return false
  888. }
  889. }
  890.  
  891. async function storeInHoverCache (metaurl, response, orgMetaUrl) {
  892. const cache = JSON.parse(await GM.getValue('hovercache', '{}'))
  893. const now = (new Date()).getTime()
  894. const timeout = 2 * 60 * 60 * 1000
  895. for (const prop in cache) {
  896. // Delete cached values, that are older than 2 hours
  897. if (now - (new Date(cache[prop].time)).getTime() > timeout) {
  898. delete cache[prop]
  899. }
  900. }
  901.  
  902. const newobj = {}
  903. for (const key in response) {
  904. newobj[key] = response[key]
  905. }
  906. newobj.responseText = '' + response.responseText
  907. newobj.cached = true
  908. if (!('time' in newobj)) {
  909. newobj.time = (new Date()).toJSON()
  910. }
  911.  
  912. cache[metaurl] = newobj
  913. if (orgMetaUrl && orgMetaUrl !== metaurl) { // Store redirect
  914. cache[orgMetaUrl] = { time: (new Date()).toJSON(), redirect: metaurl }
  915. }
  916.  
  917. await GM.setValue('hovercache', JSON.stringify(cache))
  918. }
  919.  
  920. async function isInHoverCache (metaurl) {
  921. const cache = JSON.parse(await GM.getValue('hovercache', '{}'))
  922. const now = (new Date()).getTime()
  923. const timeout = 2 * 60 * 60 * 1000
  924. for (const prop in cache) {
  925. // Delete cached values, that are older than 2 hours
  926. if (now - (new Date(cache[prop].time)).getTime() > timeout) {
  927. delete cache[prop]
  928. }
  929. }
  930.  
  931. function resolveRedirects (cacheEntry) {
  932. if (cacheEntry.redirect) {
  933. const newkey = cacheEntry.redirect
  934. if (newkey in cache) {
  935. const value = cache[newkey]
  936. delete cache[newkey]
  937. return resolveRedirects(value)
  938. }
  939. } else {
  940. return cacheEntry
  941. }
  942. return false
  943. }
  944.  
  945. if (metaurl in cache) {
  946. const value = cache[metaurl]
  947. delete cache[metaurl]
  948. return resolveRedirects(value)
  949. } else {
  950. return false
  951. }
  952. }
  953.  
  954. async function loadHoverInfo () {
  955. const cacheResponse = await isInHoverCache(current.metaurl)
  956. if (cacheResponse !== false) {
  957. console.debug(`ShowMetacriticRatings: loadHoverInfo () ${current.metaurl} found in hover cache`)
  958. if (cacheResponse.responseText.indexOf('"jsonRedirect"') !== -1) {
  959. return await handleJSONredirect(cacheResponse)
  960. }
  961. return cacheResponse
  962. }
  963. const requestURL = baseURLdatabase
  964. const requestParams = 'm=' + encodeURIComponent(current.docurl) + '&a=' + encodeURIComponent(current.metaurl)
  965.  
  966. let response = await asyncRequest({
  967. method: 'POST',
  968. url: requestURL,
  969. data: requestParams,
  970. headers: {
  971. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  972. }
  973. }).catch(function (response) {
  974. console.warn('ShowMetacriticRatings: Error 02\nurl=' + requestURL + '\nparams=' + requestParams + '\nstatus=' + response.status)
  975. })
  976.  
  977. if (response.responseText && response.responseText.indexOf('"jsonRedirect"') !== -1) {
  978. response = await handleJSONredirect(response)
  979. }
  980.  
  981. if (response.status >= 500) {
  982. // Metacritic server error, try again after 2 seconds
  983. console.warn('ShowMetacriticRatings: Metacritic server error\nwait 2s for retry\nurl=' + current.metaurl + '\nstatus=' + response.status)
  984. await delay(2000)
  985. response = await asyncRequest({ url: current.metaurl }).catch(function (response) {
  986. console.warn('ShowMetacriticRatings: Error 06\nurl=' + current.metaurl + '\nstatus=' + response.status)
  987. })
  988. if (response.status > 300) {
  989. console.warn('ShowMetacriticRatings: Metacritic server error. Error 07. Retry failed as well.\nurl=' + current.metaurl + '\nstatus=' + response.status)
  990. } else {
  991. const newobj = {}
  992. for (const key in response) {
  993. newobj[key] = response[key]
  994. }
  995. newobj.responseText = extractHoverFromFullPage(response)
  996. response = newobj
  997. }
  998. }
  999.  
  1000. if (response.responseText && response.responseText.indexOf('<title>500 Page') !== -1) {
  1001. // Hover info not available for this url, try again with GET
  1002. response = await asyncRequest({ url: current.metaurl }).catch(function (response) {
  1003. console.warn('ShowMetacriticRatings: Error 03\nurl=' + current.metaurl + '\nstatus=' + response.status)
  1004. })
  1005.  
  1006. const newobj = {}
  1007. for (const key in response) {
  1008. newobj[key] = response[key]
  1009. }
  1010. newobj.responseText = extractHoverFromFullPage(response)
  1011. response = newobj
  1012. }
  1013.  
  1014. if (!('time' in response)) {
  1015. response.time = (new Date()).toJSON()
  1016. }
  1017. if (response.status === 200 && response.responseText) {
  1018. return response
  1019. } else {
  1020. const error = new Error('ShowMetacriticRatings: loadHoverInfo()\nUrl: ' + response.finalUrl + '\nStatus: ' + response.status)
  1021. error.status = response.status
  1022. error.responseText = response.responseText
  1023. throw error
  1024. }
  1025. }
  1026.  
  1027. const current = {
  1028. metaurl: false,
  1029. docurl: false,
  1030. type: false,
  1031. data: [], // Array of raw search keys
  1032. searchTerm: false,
  1033. product: null,
  1034. broadenCounter: 0
  1035. }
  1036.  
  1037. async function loadMetacriticUrl (fromSearch) {
  1038. if (!current.metaurl) {
  1039. alert('ShowMetacriticRatings: Error 04')
  1040. return
  1041. }
  1042. const orgMetaUrl = current.metaurl
  1043. if (await isBlacklistedUrl(document.location.href, current.metaurl)) {
  1044. waitForHotkeysMETA()
  1045. return
  1046. }
  1047.  
  1048. if (await isTemporaryBlacklisted(current.metaurl)) {
  1049. console.debug(`ShowMetacriticRatings: loadMetacriticUrl(fromSearch=${fromSearch}) ${current.metaurl} is temporary blacklisted`)
  1050. waitForHotkeysMETA()
  1051. return
  1052. }
  1053.  
  1054. const response = await loadHoverInfo().catch(async function (response) {
  1055. if (response instanceof Error || (response && response.stack && response.message)) {
  1056. if (!fromSearch && ('status' in response && response.status === 404)) {
  1057. // No results
  1058. let broadenFct = broadenSearch // global broadenSearch function is the default
  1059. if ('broaden' in current.product) {
  1060. // try product 'broaden'-function if it is defined
  1061. broadenFct = current.product.broaden
  1062. }
  1063. const newData = await broadenFct(current.data.slice(0), ++current.broadenCounter, current.type)
  1064. if (newData !== current.data) {
  1065. current.data = newData
  1066. metacritic[current.type](current.docurl, current.product, ...newData)
  1067. } else if (newData === current.data) {
  1068. // Same data as before, try once again to broaden
  1069. const newData2 = await broadenFct(current.data.slice(0), ++current.broadenCounter, current.type)
  1070. if (newData2 !== current.data) {
  1071. current.data = newData2
  1072. metacritic[current.type](current.docurl, current.product, ...newData2)
  1073. } else {
  1074. console.debug('ShowMetacriticRatings: loadMetacriticUrl(): ' + ('broaden' in current.product ? 'product specific' : 'global') + " 'broaden search' did not change after " + current.broadenCounter + ' steps')
  1075. }
  1076. } else {
  1077. console.debug("ShowMetacriticRatings: loadMetacriticUrl(): Unexpected result from 'broaden'-function: ", newData)
  1078. }
  1079. } else {
  1080. console.error(`ShowMetacriticRatings: loadMetacriticUrl(fromSearch=${fromSearch}) current.metaurl = ${current.metaurl}. Error in loadHoverInfo():\n`, response)
  1081. }
  1082. }
  1083.  
  1084. if (fromSearch) {
  1085. startSearch()
  1086. }
  1087. })
  1088.  
  1089. if (await isBlacklistedUrl(document.location.href, current.metaurl)) {
  1090. waitForHotkeysMETA()
  1091. return
  1092. }
  1093.  
  1094. if (typeof response !== 'undefined') {
  1095. showHoverInfo(response, orgMetaUrl)
  1096. } else {
  1097. waitForHotkeysMETA()
  1098. }
  1099. }
  1100.  
  1101. async function startSearch () {
  1102. waitForHotkeysMETA()
  1103.  
  1104. const cache = JSON.parse(await GM.getValue('autosearchcache', '{}'))
  1105. const now = (new Date()).getTime()
  1106. const timeout = 2 * 60 * 60 * 1000
  1107. for (const prop in cache) {
  1108. // Delete cached values, that are older than 2 hours
  1109. if (now - (new Date(cache[prop].time)).getTime() > timeout) {
  1110. delete cache[prop]
  1111. }
  1112. }
  1113.  
  1114. if (current.type === 'music') {
  1115. current.searchTerm = current.data[0]
  1116. } else {
  1117. current.searchTerm = current.data.join(' ')
  1118. }
  1119. let response
  1120. if (current.searchTerm in cache) {
  1121. response = cache[current.searchTerm]
  1122. } else {
  1123. response = await asyncRequest({
  1124. method: 'POST',
  1125. url: baseURLautosearch,
  1126. data: 'search_term=' + encodeURIComponent(current.searchTerm) + '&image_size=98&search_each=1&sort_type=popular',
  1127. headers: {
  1128. Referer: current.metaurl,
  1129. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  1130. // Host: 'www.metacritic.com',
  1131. 'User-Agent': 'MetacriticUserscript Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0',
  1132. 'X-Requested-With': 'XMLHttpRequest'
  1133. }
  1134. })
  1135. response = {
  1136. time: (new Date()).toJSON(),
  1137. json: JSON.parse(response.responseText)
  1138. }
  1139. cache[current.searchTerm] = response
  1140. await GM.setValue('autosearchcache', JSON.stringify(cache))
  1141. }
  1142.  
  1143. if (!response || !('json' in response)) {
  1144. alert('ShowMetacriticRatings: Error 05')
  1145. }
  1146. const data = response.json
  1147. let multiple = false
  1148. if (data && data.autoComplete && data.autoComplete.results && data.autoComplete.results.length) {
  1149. // Remove data with wrong type
  1150. data.autoComplete = data.autoComplete.results
  1151.  
  1152. const newdata = []
  1153. data.autoComplete.forEach(function (result) {
  1154. if (metacritic2searchType(result.refType) === current.type) {
  1155. newdata.push(result)
  1156. }
  1157. })
  1158. data.autoComplete = newdata
  1159. if (data.autoComplete.length === 0) {
  1160. // No results
  1161. console.debug('ShowMetacriticRatings: No results (after filtering by type) for searchTerm=' + current.searchTerm)
  1162. } else if (data.autoComplete.length === 1) {
  1163. // One result, let's show it
  1164. if (!await isBlacklistedUrl(document.location.href, absoluteMetaURL(data.autoComplete[0].url))) {
  1165. current.metaurl = absoluteMetaURL(data.autoComplete[0].url)
  1166. loadMetacriticUrl(true)
  1167. return
  1168. }
  1169. } else {
  1170. // More than one result
  1171. multiple = true
  1172. console.debug('ShowMetacriticRatings: Multiple results for searchTerm=' + current.searchTerm)
  1173. const exactMatches = []
  1174. data.autoComplete.forEach(function (result, i) { // Try to find the correct result by matching the search term to exactly one movie title
  1175. if (current.searchTerm === result.name) {
  1176. exactMatches.push(result)
  1177. }
  1178. })
  1179. if (exactMatches.length === 1) {
  1180. // Only one exact match, let's show it
  1181. console.debug('ShowMetacriticRatings: Only one exact match for searchTerm=' + current.searchTerm)
  1182. if (!await isBlacklistedUrl(document.location.href, absoluteMetaURL(exactMatches[0].url))) {
  1183. current.metaurl = absoluteMetaURL(exactMatches[0].url)
  1184. loadMetacriticUrl(true)
  1185. return
  1186. }
  1187. }
  1188. }
  1189. } else {
  1190. console.debug('ShowMetacriticRatings: No results (at all) for searchTerm=' + current.searchTerm)
  1191. }
  1192. // HERE: multiple results or no result. The user may type "meta" now
  1193. if (multiple) {
  1194. balloonAlert('Multiple metacritic results. Type &#34;meta&#34; for manual search.', 10000, false, { bottom: 5, top: 'auto', maxWidth: 400, paddingRight: 5 }, () => openSearchBox(true))
  1195. }
  1196. }
  1197.  
  1198. function openSearchBox (search) {
  1199. let query
  1200. if (current.type === 'music') {
  1201. query = current.data[0]
  1202. } else {
  1203. query = current.data.join(' ')
  1204. }
  1205. $('#mcdiv123').remove()
  1206. const div = $('<div id="mcdiv123"></div>').appendTo(document.body)
  1207. div.css({
  1208. position: 'fixed',
  1209. bottom: 0,
  1210. left: 0,
  1211. minWidth: 300,
  1212. maxHeight: '80%',
  1213. maxWidth: 640,
  1214. overflow: 'auto',
  1215. backgroundColor: '#fff',
  1216. border: '2px solid #bbb',
  1217. borderRadius: ' 6px',
  1218. boxShadow: '0 0 3px 3px rgba(100, 100, 100, 0.2)',
  1219. color: '#000',
  1220. padding: ' 3px',
  1221. zIndex: '2147483601'
  1222. })
  1223. $('<input type="text" size="60" id="mcisearchquery" style="background:white;color:black;">').appendTo(div).focus().val(query).on('keypress', function (e) {
  1224. const code = e.keyCode || e.which
  1225. if (code === 13) { // Enter key
  1226. searchBoxSearch(e, $('#mcisearchquery').val())
  1227. }
  1228. })
  1229. $('<button id="mcisearchbutton" style="background:silver;color:black;">').text('Search').appendTo(div).click((ev) => searchBoxSearch(ev, $('#mcisearchquery').val()))
  1230. }
  1231. async function searchBoxSearch (ev, query) {
  1232. if (!query) { // Use values from search form
  1233. query = current.searchTerm
  1234. }
  1235.  
  1236. const type = searchType2metacritic(current.type)
  1237.  
  1238. const style = document.createElement('style')
  1239. style.type = 'text/css'
  1240. style.innerHTML = CSS
  1241. document.head.appendChild(style)
  1242.  
  1243. const div = $('#mcdiv123')
  1244. const loader = $('<div style="width:20px; height:20px;display:inline-block" class="grespinner"></div>').appendTo($('#mcisearchbutton'))
  1245.  
  1246. const url = baseURLsearch.replace('{type}', encodeURIComponent(type)).replace('{query}', encodeURIComponent(query))
  1247.  
  1248. const response = await asyncRequest({
  1249. url: url,
  1250. data: 'search_term=' + encodeURIComponent(current.searchTerm) + '&image_size=98&search_each=1&sort_type=popular',
  1251. headers: {
  1252. Referer: url,
  1253. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  1254. // Host: 'www.metacritic.com',
  1255. 'User-Agent': 'MetacriticUserscript ' + navigator.userAgent
  1256. }
  1257. }).catch(function (response) {
  1258. alert('Search failed!\n' + response.finalUrl + '\nStatus: ' + response.status + '\n' + response.responseText ? response.responseText.substring(0, 500) : 'Empty response')
  1259. })
  1260.  
  1261. const results = []
  1262. if (!~response.responseText.indexOf('No search results found.')) {
  1263. const d = $('<html>').html(response.responseText)
  1264. d.find('ul.search_results.module .result').each(function () {
  1265. results.push(this.innerHTML)
  1266. })
  1267. }
  1268.  
  1269. if (results && results.length > 0) {
  1270. // Show results
  1271. loader.remove()
  1272.  
  1273. const accept = function (ev) {
  1274. const parentDiv = $(this.parentNode)
  1275. const a = parentDiv.find("a[href*='metacritic.com']")
  1276. const metaurl = a.attr('href')
  1277. const docurl = document.location.href
  1278.  
  1279. const resultDivParent = parentDiv.parent()
  1280. resultDivParent.html('')
  1281. resultDivParent.append(loader)
  1282.  
  1283. removeFromBlacklist(docurl, metaurl).then(function () {
  1284. addToMap(docurl, metaurl).then(function () {
  1285. current.metaurl = metaurl
  1286. loadMetacriticUrl().then(() => loader.remove())
  1287. })
  1288. })
  1289. }
  1290. const denyAll = function (ev) {
  1291. const docurl = document.location.href
  1292. $('#mcdiv123searchresults').find("div.result a[href*='metacritic.com']").each(function () {
  1293. addToBlacklist(docurl, this.href)
  1294. })
  1295. }
  1296.  
  1297. const resultdiv = $('#mcdiv123searchresults').length ? $('#mcdiv123searchresults').html('') : $('<div id="mcdiv123searchresults"></div>').css('max-width', '95%').appendTo(div)
  1298. results.forEach(function (html) {
  1299. const singleresult = $('<div class="result"></div>').html(fixMetacriticURLs(html) + '<div style="clear:left"></div>').appendTo(resultdiv)
  1300. $('<span title="Assist us: This is the correct entry!" style="cursor:pointer; color:green; font-size: 13px;">&check;</span>').prependTo(singleresult).click(accept)
  1301. })
  1302. resultdiv.find('.metascore_w.album').removeClass('album') // Remove some classes
  1303. resultdiv.find('.must-see').remove() // Remove some elements
  1304.  
  1305. const sub = $('#mcdiv123 .sub').length ? $('#mcdiv123 .sub').html('') : $('<div class="sub"></div>').appendTo(div)
  1306. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="' + url + '" title="Open Metacritic">' + decodeURI(url.replace('https://www.', '@')) + '</a>').appendTo(sub)
  1307. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px;">&#10062;</span>').appendTo(sub).click(function () {
  1308. document.body.removeChild(this.parentNode.parentNode)
  1309. })
  1310. $('<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() })
  1311. } else {
  1312. // No results
  1313. loader.remove()
  1314. const resultdiv = $('#mcdiv123searchresults').length ? $('#mcdiv123searchresults').html('') : $('<div id="mcdiv123searchresults"></div>').appendTo(div)
  1315. resultdiv.html('No search results.')
  1316.  
  1317. const sub = $('#mcdiv123 .sub').length ? $('#mcdiv123 .sub').html('') : $('<div class="sub"></div>').appendTo(div)
  1318. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="' + url + '" title="Open Metacritic">' + decodeURI(url.replace('https://www.', '@')) + '</a>').appendTo(sub)
  1319. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px;">&#10062;</span>').appendTo(sub).click(function () {
  1320. document.body.removeChild(this.parentNode.parentNode)
  1321. })
  1322. }
  1323. }
  1324.  
  1325. function showHoverInfo (response, orgMetaUrl) {
  1326. const html = fixMetacriticURLs(response.responseText)
  1327. const time = new Date(response.time)
  1328. const url = response.finalUrl
  1329.  
  1330. $('#mcdiv123').remove()
  1331. const div = $('<div id="mcdiv123"></div>').appendTo(document.body)
  1332. div.css({
  1333. position: 'fixed',
  1334. bottom: 0,
  1335. left: 0,
  1336. minWidth: 300,
  1337. backgroundColor: '#fff',
  1338. border: '2px solid #bbb',
  1339. borderRadius: ' 6px',
  1340. boxShadow: '0 0 3px 3px rgba(100, 100, 100, 0.2)',
  1341. color: '#000',
  1342. padding: ' 3px',
  1343. zIndex: '2147483601'
  1344. })
  1345.  
  1346. // Functions for communication between page and iframe
  1347. // Mozilla can access parent.document
  1348. // Chrome can use postMessage()
  1349. let frameStatus = false // if this remains false, loading the frame content failed. A reason could be "Content Security Policy"
  1350. function loadExternalImage (url, myframe) {
  1351. // Load external image, bypass CSP
  1352. GM.xmlHttpRequest({
  1353. method: 'GET',
  1354. url: url,
  1355. responseType: 'arraybuffer',
  1356. onload: function (response) {
  1357. myframe.contentWindow.postMessage({
  1358. mcimessage_imgLoaded: true,
  1359. mcimessage_imgData: response.response,
  1360. mcimessage_imgOrgSrc: url
  1361. }, '*')
  1362. }
  1363. })
  1364. }
  1365. const functions = {
  1366. parent: function () {
  1367. const f = parent.document.getElementById('mciframe123')
  1368. let lastdiff = -200000
  1369. window.addEventListener('message', function (e) {
  1370. if (typeof e.data !== 'object') {
  1371. return
  1372. } else if ('mcimessage0' in e.data) {
  1373. frameStatus = true // Frame content was loaded successfully
  1374. } else if ('mcimessage1' in e.data) {
  1375. f.style.width = parseInt(f.style.width) + 10 + 'px'
  1376. if (e.data.heightdiff === lastdiff) {
  1377. f.style.height = parseInt(f.style.height) + 5 + 'px'
  1378. }
  1379. lastdiff = e.data.heightdiff
  1380. } else if ('mcimessage2' in e.data) {
  1381. f.style.height = parseInt(f.style.height) + 15 + 'px'
  1382. f.style.width = '400px'
  1383. } else if ('mcimessage_loadImg' in e.data) {
  1384. loadExternalImage(e.data.mcimessage_imgUrl, f)
  1385. } else {
  1386. return
  1387. }
  1388. if (f.contentWindow != null) {
  1389. f.contentWindow.postMessage({
  1390. mcimessage3: true,
  1391. mciframe123_clientHeight: f.clientHeight,
  1392. mciframe123_clientWidth: f.clientWidth
  1393. }, '*')
  1394. }
  1395. })
  1396. },
  1397. frame: function () {
  1398. parent.postMessage({ mcimessage0: true }, '*') // Loading frame content was successfull
  1399.  
  1400. let i = 0
  1401. window.addEventListener('message', function (e) {
  1402. if (typeof e.data === 'object' && 'mcimessage_imgLoaded' in e.data) {
  1403. // Load external image
  1404. const arrayBufferView = new Uint8Array(e.data.mcimessage_imgData)
  1405. const blob = new Blob([arrayBufferView], { type: 'image/jpeg' })
  1406. const urlCreator = window.URL || window.webkitURL
  1407. const imageUrl = urlCreator.createObjectURL(blob)
  1408. const img = failedImages[e.data.mcimessage_imgOrgSrc]
  1409. img.src = imageUrl
  1410. }
  1411.  
  1412. if (!('mcimessage3' in e.data)) return
  1413.  
  1414. if (e.data.mciframe123_clientHeight < document.body.scrollHeight && i < 100) {
  1415. parent.postMessage({ mcimessage1: 1, heightdiff: document.body.scrollHeight - e.data.mciframe123_clientHeight }, '*')
  1416. i++
  1417. }
  1418. if (i >= 100) {
  1419. parent.postMessage({ mcimessage2: 1 }, '*')
  1420. i = 0
  1421. }
  1422. })
  1423. parent.postMessage({ mcimessage1: 1, heightdiff: -100000 }, '*')
  1424. }
  1425.  
  1426. }
  1427.  
  1428. const css = `#hover_div .clr { clear: both}
  1429. #hover_div .fl{float: left}
  1430. #hover_div { background-color: #fff; color: #666; font-family:Arial,Helvetica,sans-serif; font-size:12px; font-weight:400; font-style:normal;}
  1431. #hover_div .hoverinfo .hover_left { float: left}
  1432. #hover_div .hoverinfo .product_image_wrapper { color: #999; font-size: 6px; font-weight: normal; min-height: 98px; min-width: 98px;}
  1433. #hover_div .hoverinfo .product_image_wrapper a { color: #999; font-size: 6px; font-weight: normal;}
  1434. #hover_div a * { cursor: pointer}
  1435. #hover_div a { color: #09f; font-weight: bold;}
  1436. #hover_div a:link, #hover_div a:visited { text-decoration: none;}
  1437. #hover_div a:hover { text-decoration: underline;}
  1438. #hover_div .hoverinfo .hover_right { float: left; margin-left: 15px; max-width: 395px;}
  1439. #hover_div .hoverinfo .product_title { color: #333; font-family: georgia,serif; font-size: 24px; line-height: 26px; margin-bottom: 10px;}
  1440. #hover_div .hoverinfo .product_title a { color:#333; font-family: georgia,serif; font-size: 24px;}
  1441. #hover_div .hoverinfo .summary_detail.publisher, .hoverinfo .summary_detail.release_data { float: left}
  1442. #hover_div .hoverinfo .summary_detail { font-size: 11px; margin-bottom: 10px;}
  1443. #hover_div .hoverinfo .summary_detail.product_credits a { color: #999; font-weight: normal; }
  1444. #hover_div .hoverinfo .hr { background-color: #ccc; height: 2px; margin: 15px 0 10px;}
  1445. #hover_div .hoverinfo .hover_scores { width: 100%; border-collapse: collapse; border-spacing: 0;}
  1446. #hover_div .hoverinfo .hover_scores td.num { width: 39px}
  1447. #hover_div .hoverinfo .hover_scores td { vertical-align: middle}
  1448. #hover_div caption, #hover_div th, #hover_div td { font-weight: normal; text-align: left;}
  1449. #hover_div .metascore_anchor, #hover_div a.metascore_w { text-decoration: none !important}
  1450. #hover_div span.metascore_w, #hover_div a.metascore_w { display: inline-block; padding:0px;}
  1451. .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;}
  1452. #hover_div .metascore, #hover_div .metascore a, #hover_div .avguserscore, #hover_div .avguserscore a { color: #fff}
  1453. #hover_div .critscore, #hover_div .critscore a, #hover_div .userscore, #hover_div .userscore a { color: #333}
  1454. .score_tbd { background: #eaeaea; color: #333; font-size: 14px;}
  1455. #hover_div .score_tbd a { color: #333}
  1456. #hover_div .negative,#hover_div .score_terrible,#hover_div .score_unfavorable,#hover_div .carousel_set a.product_terrible:hover,#hover_div .carousel_set a.product_unfavorable:hover { background-color: #f00}
  1457. #hover_div.mixed, .neutral,#hover_div .score_mixed,#hover_div .carousel_set a.product_mixed:hover { background-color: #fc3; color: #333;}
  1458. #hover_div .score_mixed a { color: #333}
  1459. #hover_div .positive,#hover_div .score_favorable,#hover_div .score_outstanding,#hover_div .carousel_set a.product_favorable:hover,#hover_div .carousel_set a.product_outstanding:hover { background-color: #6c3}
  1460. .critscore_terrible, .critscore_unfavorable { border-color: #f00}
  1461. .critscore_mixed { border-color: #fc3}
  1462. .critscore_favorable, .critscore_outstanding { border-color: #6c3}
  1463. .metascore .score_total, .userscore .score_total { display: none; visibility: hidden;}
  1464. .hoverinfo .metascore_label, .hoverinfo .userscore_label { font-size: 12px; font-weight: bold; line-height: 16px; margin-top: 2%;}
  1465. .hoverinfo .metascore_review_count, .hoverinfo .userscore_review_count { font-size: 11px}
  1466. .hoverinfo .hover_scores td { vertical-align: middle}
  1467. .hoverinfo .hover_scores td.num { width: 39px}
  1468. .hoverinfo .hover_scores td.usr.num { padding-left: 20px}
  1469. .metascore_anchor, a.metascore_w { text-decoration: none !important}
  1470. .metascore_w.album { padding-top:0px; !important}
  1471. .metascore_w.user { border-radius: 55%; color: #fff;}
  1472. .metascore_anchor, .metascore_w.album { padding: 0px;!important, padding-top: 0px;!important}
  1473. a.metascore_w { text-decoration: none!important}
  1474. .metascore_anchor:hover { text-decoration: none!important}
  1475. .metascore_w:hover { text-decoration: none!important}
  1476. span.metascore_w, a.metascore_w { display: inline-block}
  1477. .metascore_w.xlarge, .metascore_w.xl { font-size: 42px}
  1478. .metascore_w.large, .metascore_w.lrg { font-size: 25px}
  1479. .m .metascore_w.medium, .m .metascore_w.med { font-size: 19px}
  1480. .metascore_w.med_small { font-size: 14px}
  1481. .metascore_w.small, .metascore_w.sm { font-size: 12px}
  1482. .metascore_w.tiny { height: 1.9em; font-size: 11px; line-height: 1.9em;}
  1483. .metascore_w.user { border-radius: 55%; color: #fff;}
  1484. .metascore_w.user.small, .metascore_w.user.sm { font-size: 11px}
  1485. .metascore_w.tbd, .metascore_w.score_tbd { color: #000!important; background-color: #ccc;}
  1486. .metascore_w.tbd.hide_tbd, .metascore_w.score_tbd.hide_tbd { visibility: hidden}
  1487. .metascore_w.tbd.no_tbd, .metascore_w.score_tbd.no_tbd { display: none}
  1488. .metascore_w.noscore::before, .metascore_w.score_noscore::before { content: '\u2022\u2022\u2022'}
  1489. .metascore_w.noscore, .metascore_w.score_noscore { color: #fff!important; background-color: #ccc;}
  1490. .metascore_w.rip, .metascore_w.score_rip { border-radius: 4px; color: #fff!important; background-color: #999;}
  1491. .metascore_w.negative, .metascore_w.score_terrible, .metascore_w.score_unfavorable { background-color: #f00}
  1492. .metascore_w.mixed, .metascore_w.forty, .metascore_w.game.fifty, .metascore_w.score_mixed { background-color: #fc3}
  1493. .metascore_w.positive, .metascore_w.sixtyone, .metascore_w.game.seventyfive, .metascore_w.score_favorable, .metascore_w.score_outstanding { background-color: #6c3}
  1494. .metascore_w.indiv { height: 1.9em; width: 1.9em; font-size: 15px; line-height: 1.9em;}
  1495. .metascore_w.indiv.large, .metascore_w.indiv.lrg { font-size: 24px}
  1496. .m .metascore_w.indiv.medium, .m .metascore_w.indiv.med { font-size: 16px}
  1497. .metascore_w.indiv.small, .metascore_w.indiv.sm { font-size: 11px}
  1498. .metascore_w.indiv.perfect { padding-right: 1px}
  1499. .hover_esite { display:none; }
  1500. .promo_amazon .esite_btn { margin: 3px 0 0 7px;}
  1501. .esite_amazon { background-color: #fdc354; border: 1px solid #aaa;}
  1502. .esite_label_wrapper { display:none;}
  1503. .esite_btn { border-radius: 4px; color: #222; font-size: 12px; height: 40px; line-height: 40px; width: 120px;}
  1504. .chart{background-color:inherit!important;margin-top:-3px}
  1505. .chart_bg{width:100%;border-top:3px solid rgba(150,150,150,0.3)}
  1506. .chart .bar{width:100%;height:3px}
  1507. .chart .count{font-size:10px}`
  1508.  
  1509. let framesrc = 'data:text/html,'
  1510. framesrc += encodeURIComponent('<!DOCTYPE html>\
  1511. <html lang="en">\
  1512. <head>\
  1513. <meta charset="utf-8">\
  1514. <title>Metacritic info</title>\
  1515. <style>body { margin:0px; padding:0px; background:white; }' + css +
  1516. '\
  1517. </style>\
  1518. <script>\
  1519. const failedImages = {};\
  1520. function detectCSP(img) {\
  1521. if(img.complete && (!img.naturalWidth || !img.naturalHeight)) {\
  1522. return true;\
  1523. }\
  1524. return false;\
  1525. }\
  1526. function findCSPerrors() {\
  1527. const imgs = document.querySelectorAll("img");\
  1528. for(let i = 0; i < imgs.length; i++) {\
  1529. if(imgs[i].complete && detectCSP(imgs[i])) {\
  1530. fixCSP(imgs[i]);\
  1531. }\
  1532. }\
  1533. }\
  1534. function fixCSP(img) {\
  1535. console.debug("ShowMetacriticRatings(iFrame): Loading image failed. Bypassing CSP...");\
  1536. failedImages[img.src] = img;\
  1537. parent.postMessage({"mcimessage_loadImg":true, "mcimessage_imgUrl": img.src},"*"); \
  1538. }\
  1539. function on_load() {\
  1540. (' + functions.frame.toString() + ')();\
  1541. window.setTimeout(findCSPerrors, 500);\
  1542. \
  1543. }\
  1544. </script>\
  1545. </head>\
  1546. <body onload="on_load();">\
  1547. <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">\
  1548. <div class="hover_content">' + html + '</div>\
  1549. </div>\
  1550. </body>\
  1551. </html>')
  1552.  
  1553. const frame = $('<iframe></iframe>').appendTo(div)
  1554. frame.attr('id', 'mciframe123')
  1555. frame.attr('src', framesrc)
  1556. frame.attr('scrolling', 'auto')
  1557. frame.css({
  1558. width: 380,
  1559. height: 150,
  1560. border: 'none'
  1561. })
  1562.  
  1563. window.setTimeout(function () {
  1564. if (!frameStatus) { // Loading frame content failed.
  1565. // Directly inject the html without an iframe (this may break the site or the metacritic)
  1566. console.debug('ShowMetacriticRatings: Loading iframe content failed. Injecting directly.')
  1567. $('head').append('<style>' + css + '</style>')
  1568. const 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">\
  1569. <div class="hover_content">' + html + '</div>\
  1570. </div>')
  1571. frame.replaceWith(noframe)
  1572. }
  1573. }, 2000)
  1574.  
  1575. functions.parent()
  1576.  
  1577. const sub = $('<div></div>').appendTo(div)
  1578. $('<time style="color:#b6b6b6; font-size: 11px;" datetime="' + time + '" title="' + time.toLocaleTimeString() + ' ' + time.toLocaleDateString() + '">' + minutesSince(time) + '</time>').appendTo(sub)
  1579. $('<a style="color:#b6b6b6; font-size: 11px;" target="_blank" href="' + url + '" title="Open Metacritic">' + decodeURI(url.replace('https://www.', '@')) + '</a>').appendTo(sub)
  1580. $('<span title="Hide me" style="cursor:pointer; float:right; color:#b6b6b6; font-size: 11px; padding-left:5px;">&#10062;</span>').data('url', current.metaurl).appendTo(sub).click(function () {
  1581. const metaurl = $(this).data('url')
  1582. addToTemporaryBlacklist(metaurl)
  1583. document.body.removeChild(this.parentNode.parentNode)
  1584. })
  1585.  
  1586. $('<span title="Assist us: This is the correct entry!" style="cursor:pointer; float:right; color:green; font-size: 11px;">&check;</span>').data('url', current.metaurl).appendTo(sub).click(function () {
  1587. const docurl = document.location.href
  1588. const metaurl = $(this).data('url')
  1589. addToMap(docurl, metaurl).then(function (r) {
  1590. balloonAlert('Thanks for your submission!\n\nSaved as a correct entry.\n\n' + r[0] + '\n' + r[1], 6000, 'Success')
  1591. })
  1592. })
  1593. $('<span title="Assist us: This is NOT the correct entry!" style="cursor:pointer; float:right; color:crimson; font-size: 11px;">&cross;</span>').data('url', current.metaurl).appendTo(sub).click(function () {
  1594. if (!confirm('This is NOT the correct entry!\n\nAdd to blacklist?')) return
  1595. const docurl = document.location.href
  1596. const metaurl = $(this).data('url')
  1597. addToBlacklist(docurl, metaurl).then(function (r) {
  1598. balloonAlert('Thanks for your submission!\n\nSaved to blacklist.\n\n' + r[0] + '\n' + r[1], 6000, 'Success')
  1599. })
  1600.  
  1601. openSearchBox(true)
  1602. })
  1603.  
  1604. // Store response in cache:
  1605. if (!('cached' in response)) {
  1606. storeInHoverCache(current.metaurl, response, orgMetaUrl)
  1607. }
  1608. }
  1609.  
  1610. function metacritic_general_product_setup () {
  1611. current.broadenCounter = 0
  1612. }
  1613.  
  1614. const metacritic = {
  1615. mapped: function metacriticMapped (docurl, product, metaurl, type) {
  1616. // url was in the map/whitelist
  1617. current.data = []
  1618. current.docurl = docurl
  1619. current.product = product
  1620. current.metaurl = metaurl
  1621. current.type = type
  1622. current.searchTerm = null
  1623. loadMetacriticUrl()
  1624. },
  1625. music: function metacriticMusic (docurl, product, artistname, albumname) {
  1626. current.data = [albumname.trim(), artistname.trim()]
  1627. artistname = name2metacritic(artistname)
  1628. albumname = albumname.replace('&', ' ')
  1629. albumname = name2metacritic(albumname)
  1630. current.docurl = docurl
  1631. current.product = product
  1632. current.metaurl = baseURLmusic + albumname + '/' + artistname
  1633. current.type = 'music'
  1634. current.searchTerm = albumname + '/' + artistname
  1635. loadMetacriticUrl()
  1636. },
  1637. movie: function metacriticMovie (docurl, product, moviename) {
  1638. current.data = [moviename.trim()]
  1639. moviename = name2metacritic(moviename)
  1640. current.docurl = docurl
  1641. current.product = product
  1642. current.metaurl = baseURLmovie + moviename
  1643. current.type = 'movie'
  1644. current.searchTerm = moviename
  1645. loadMetacriticUrl()
  1646. },
  1647. tv: function metacriticTv (docurl, product, seriesname) {
  1648. current.data = [seriesname.trim()]
  1649. seriesname = name2metacritic(seriesname)
  1650. current.docurl = docurl
  1651. current.product = product
  1652. current.metaurl = baseURLtv + seriesname
  1653. current.type = 'tv'
  1654. current.searchTerm = seriesname
  1655. loadMetacriticUrl()
  1656. },
  1657. pcgame: function metacriticPcgame (docurl, product, gamename) {
  1658. current.data = [gamename.trim()]
  1659. gamename = name2metacritic(gamename)
  1660. current.docurl = docurl
  1661. current.product = product
  1662. current.metaurl = baseURLpcgame + gamename
  1663. current.type = 'pcgame'
  1664. current.searchTerm = gamename
  1665. loadMetacriticUrl()
  1666. },
  1667. ps4game: function metacriticPs4game (docurl, product, gamename) {
  1668. current.data = [gamename.trim()]
  1669. gamename = name2metacritic(gamename)
  1670. current.docurl = docurl
  1671. current.product = product
  1672. current.metaurl = baseURLps4 + gamename
  1673. current.type = 'ps4game'
  1674. current.searchTerm = gamename
  1675. loadMetacriticUrl()
  1676. },
  1677. xonegame: function metacriticXonegame (docurl, product, gamename) {
  1678. current.data = [gamename.trim()]
  1679. gamename = name2metacritic(gamename)
  1680. current.docurl = docurl
  1681. current.product = product
  1682. current.metaurl = baseURLxone + gamename
  1683. current.type = 'xonegame'
  1684. current.searchTerm = gamename
  1685. loadMetacriticUrl()
  1686. }
  1687. }
  1688.  
  1689. const Always = () => true
  1690. const sites = {
  1691. bandcamp: {
  1692. host: ['bandcamp.com'],
  1693. condition: () => unsafeWindow && unsafeWindow.TralbumData && unsafeWindow.TralbumData.current,
  1694. products: [{
  1695. condition: Always,
  1696. type: 'music',
  1697. data: () => [unsafeWindow.TralbumData.artist, unsafeWindow.TralbumData.current.title]
  1698. }]
  1699. },
  1700. itunes: {
  1701. host: ['itunes.apple.com'],
  1702. condition: Always,
  1703. products: [{
  1704. condition: () => ~document.location.href.indexOf('/movie/'),
  1705. type: 'movie',
  1706. data: () => parseLDJSON('name', (j) => (j['@type'] === 'Movie'))
  1707. },
  1708. {
  1709. condition: () => ~document.location.href.indexOf('/tv-season/'),
  1710. type: 'tv',
  1711. data: function () {
  1712. let name = parseLDJSON('name', (j) => (j['@type'] === 'TVSeries'))
  1713. if (~name.indexOf(', Season')) {
  1714. name = name.split(', Season')[0]
  1715. }
  1716. return name
  1717. }
  1718. },
  1719. {
  1720. condition: () => ~document.location.href.indexOf('/album/'),
  1721. type: 'music',
  1722. data: function () {
  1723. const ld = parseLDJSON(['name', 'byArtist'], (j) => (j['@type'] === 'MusicAlbum'))
  1724. const album = ld[0]
  1725. const artist = 'name' in ld[1] ? ld[1].name : ld[1].map(x => x.name).join(' ')
  1726. return [artist, album]
  1727. }
  1728. }]
  1729. },
  1730. 'music.apple': {
  1731. host: ['music.apple.com'],
  1732. condition: Always,
  1733. products: [{
  1734. condition: () => ~document.location.href.indexOf('/album/') && parseLDJSON(['name', 'byArtist'], (j) => (j['@type'] === 'MusicAlbum')).length > 1,
  1735. type: 'music',
  1736. data: function () {
  1737. const ld = parseLDJSON(['name', 'byArtist'], (j) => (j['@type'] === 'MusicAlbum'))
  1738. const album = ld[0]
  1739. const artist = 'name' in ld[1] ? ld[1].name : ld[1].map(x => x.name).join(' ')
  1740. return [artist, album]
  1741. }
  1742. }]
  1743. },
  1744. googleplay: {
  1745. host: ['play.google.com'],
  1746. condition: Always,
  1747. products: [
  1748. {
  1749. condition: () => ~document.location.href.indexOf('/album/'),
  1750. type: 'music',
  1751. data: () => [document.querySelector('[itemprop="byArtist"] meta[itemprop="name"]').content, document.querySelector('[itemtype="https://schema.org/MusicAlbum"] meta[itemprop="name"]').content]
  1752. },
  1753. {
  1754. condition: () => ~document.location.href.indexOf('/movies/details/'),
  1755. type: 'movie',
  1756. data: () => document.querySelector('*[itemprop=name]').textContent
  1757. }
  1758. ]
  1759. },
  1760. imdb: {
  1761. host: ['imdb.com'],
  1762. condition: () => !~document.location.pathname.indexOf('/mediaviewer') && !~document.location.pathname.indexOf('/mediaindex') && !~document.location.pathname.indexOf('/videoplayer'),
  1763. products: [
  1764. {
  1765. condition: function () {
  1766. const e = document.querySelector("meta[property='og:type']")
  1767. if (e && e.content === 'video.movie') {
  1768. return true
  1769. } else if (document.querySelector('[data-testid="hero-title-block__title"]') && !document.querySelector('[data-testid="hero-subnav-bar-left-block"] a[href*="episodes/"]')) {
  1770. // New design 2020-12
  1771. return true
  1772. }
  1773. return false
  1774. },
  1775. type: 'movie',
  1776. data: function () {
  1777. if (document.querySelector('[data-testid="hero-title-block__title"]')) {
  1778. // New design 2020-12
  1779. return document.querySelector('[data-testid="hero-title-block__title"]').textContent
  1780. } else if (document.querySelector("meta[property='og:title']") && document.querySelector("meta[property='og:title']").content) { // English/Worldwide title, this is the prefered title for search
  1781. let name = document.querySelector("meta[property='og:title']").content.trim()
  1782. if (name.indexOf('- IMDb') !== -1) {
  1783. name = name.replace('- IMDb', '').trim()
  1784. }
  1785. name = name.replace(/\(\d{4}\)/, '').trim()
  1786. return name
  1787. } else if (document.querySelector('.originalTitle') && document.querySelector('.title_wrapper h1')) { // Use English title 2018
  1788. return document.querySelector('.title_wrapper h1').firstChild.textContent.trim()
  1789. } else if (document.querySelector('script[type="application/ld+json"]')) { // Use original language title
  1790. return parseLDJSON('name')
  1791. } else if (document.querySelector('h1[itemprop=name]')) { // Movie homepage (New design 2015-12)
  1792. return document.querySelector('h1[itemprop=name]').firstChild.textContent.trim()
  1793. } else if (document.querySelector('*[itemprop=name] a') && document.querySelector('*[itemprop=name] a').firstChild.textContent) { // Subpage of a move
  1794. return document.querySelector('*[itemprop=name] a').firstChild.textContent.trim()
  1795. } else if (document.querySelector('.title-extra[itemprop=name]')) { // Movie homepage: sub-/alternative-/original title
  1796. return document.querySelector('.title-extra[itemprop=name]').firstChild.textContent.replace(/"/g, '').trim()
  1797. } else if (document.querySelector('*[itemprop=name]')) { // Movie homepage (old design)
  1798. return document.querySelector('*[itemprop=name]').firstChild.textContent.trim()
  1799. } else {
  1800. return document.title.match(/(.+?)\s+(\(\d+\))? - IMDb/)[1]
  1801. }
  1802. }
  1803. },
  1804. {
  1805. condition: function () {
  1806. const e = document.querySelector("meta[property='og:type']")
  1807. if (e && e.content === 'video.tv_show') {
  1808. return true
  1809. } else if (document.querySelector('[data-testid="hero-subnav-bar-left-block"] a[href*="episodes/"]')) {
  1810. // New design 2020-12
  1811. return true
  1812. }
  1813. return false
  1814. },
  1815. type: 'tv',
  1816. data: function () {
  1817. if (document.querySelector('[data-testid="hero-title-block__title"]')) {
  1818. // New design 2020-12
  1819. return document.querySelector('[data-testid="hero-title-block__title"]').textContent
  1820. } else if (document.querySelector('*[itemprop=name]')) {
  1821. return document.querySelector('*[itemprop=name]').textContent
  1822. } else if (document.querySelector('script[type="application/ld+json"]')) {
  1823. const jsonld = JSON.parse(document.querySelector('script[type="application/ld+json"]').innerText)
  1824. return jsonld.name
  1825. } else {
  1826. return document.title.match(/(.+?)\s+\(TV/)[1]
  1827. }
  1828. }
  1829. }
  1830. ]
  1831. },
  1832. steam: {
  1833. host: ['store.steampowered.com'],
  1834. condition: () => document.querySelector('*[itemprop=name]'),
  1835. products: [{
  1836. condition: Always,
  1837. type: 'pcgame',
  1838. data: () => document.querySelector('*[itemprop=name]').textContent
  1839. }]
  1840. },
  1841. rottentomatoes: {
  1842. host: ['rottentomatoes.com'],
  1843. condition: Always,
  1844. products: [{
  1845. condition: () => document.location.pathname.startsWith('/m/'),
  1846. type: 'movie',
  1847. data: () => document.querySelector('h1').firstChild.textContent
  1848. },
  1849. {
  1850. condition: () => document.location.pathname.startsWith('/tv/'),
  1851. type: 'tv',
  1852. data: () => unsafeWindow.BK.TvSeriesTitle
  1853. }
  1854. ]
  1855. },
  1856. serienjunkies: {
  1857. host: ['www.serienjunkies.de'],
  1858. condition: Always,
  1859. products: [{
  1860. condition: () => Always,
  1861. type: 'tv',
  1862. data: () => parseLDJSON('name', (j) => (j['@type'] === 'TVSeries'))
  1863. }]
  1864. },
  1865. gamespot: {
  1866. host: ['gamespot.com'],
  1867. condition: () => document.querySelector('[itemprop=device]'),
  1868. products: [
  1869. {
  1870. condition: () => ~$('[itemprop=device]').text().indexOf('PC'),
  1871. type: 'pcgame',
  1872. data: () => parseLDJSON('name', (j) => (j['@type'] === 'VideoGame'))
  1873. },
  1874. {
  1875. condition: () => ~$('[itemprop=device]').text().indexOf('PS4'),
  1876. type: 'ps4game',
  1877. data: () => parseLDJSON('name', (j) => (j['@type'] === 'VideoGame'))
  1878. },
  1879. {
  1880. condition: () => ~$('[itemprop=device]').text().indexOf('XONE'),
  1881. type: 'xonegame',
  1882. data: () => parseLDJSON('name', (j) => (j['@type'] === 'VideoGame'))
  1883. }
  1884. ]
  1885. },
  1886. amazon: {
  1887. host: ['amazon.'],
  1888. condition: Always,
  1889. products: [
  1890. {
  1891. condition: () => document.location.hostname === 'music.amazon.com' && document.location.pathname.startsWith('/albums/') && document.querySelector('.viewTitle'), // "Amazon Music Unlimited" page
  1892. type: 'music',
  1893. data: function () {
  1894. const artist = document.querySelector('.artistLink').textContent.trim()
  1895. let title = document.querySelector('.viewTitle').textContent.trim()
  1896. title = title.replace(/\[([^\]]*)\]/g, '').trim() // Remove [brackets] and their content
  1897. if (artist && title) {
  1898. return [artist, title]
  1899. }
  1900. return false
  1901. }
  1902. },
  1903. {
  1904. condition: function () { // "Normal amazon" page
  1905. try {
  1906. if (document.querySelector('.nav-categ-image').alt.toLowerCase().indexOf('musi') !== -1) {
  1907. return true
  1908. }
  1909. } catch (e) {}
  1910. const music = ['Music', 'Musique', 'Musik', 'Música', 'Musica', '音楽']
  1911. return music.some(function (s) {
  1912. if (~document.title.indexOf(s)) {
  1913. return true
  1914. } else {
  1915. return false
  1916. }
  1917. })
  1918. },
  1919. type: 'music',
  1920. data: function () {
  1921. let artist = false
  1922. let title = false
  1923. if (document.querySelector('#ProductInfoArtistLink')) {
  1924. artist = document.querySelector('#ProductInfoArtistLink').textContent.trim()
  1925. } else if (document.querySelector('#bylineInfo .author>*')) {
  1926. artist = document.querySelector('#bylineInfo .author>*').textContent.trim()
  1927. }
  1928.  
  1929. if (document.querySelector('#dmusicProductTitle_feature_div')) {
  1930. title = document.querySelector('#dmusicProductTitle_feature_div').textContent.trim()
  1931. title = title.replace(/\[([^\]]*)\]/g, '').trim() // Remove [brackets] and their content
  1932. } else if (document.querySelector('#productTitle')) {
  1933. title = document.querySelector('#productTitle').textContent.trim()
  1934. title = title.replace(/\[([^\]]*)\]/g, '').trim() // Remove [brackets] and their content
  1935. }
  1936. return [artist, title]
  1937. }
  1938. },
  1939. {
  1940. condition: () => (document.querySelector('[data-automation-id=title]') && (
  1941. document.getElementsByClassName('av-season-single').length ||
  1942. document.querySelector('[data-automation-id="num-of-seasons-badge"]') ||
  1943. document.getElementById('tab-selector-episodes') ||
  1944. document.getElementById('av-droplist-av-atf-season-selector')
  1945. )),
  1946. type: 'tv',
  1947. data: () => document.querySelector('[data-automation-id=title]').textContent.trim()
  1948. },
  1949. {
  1950. condition: () => ((
  1951. document.getElementsByClassName('av-season-single').length ||
  1952. document.querySelector('[data-automation-id="num-of-seasons-badge"]') ||
  1953. document.getElementById('tab-selector-episodes') ||
  1954. document.getElementById('av-droplist-av-atf-season-selector')
  1955. ) && Array.from(document.querySelectorAll('script[type="text/template"]')).map(e => e.innerHTML.match(/parentTitle"\s*:\s*"(.+?)"/)).some((x) => x != null)),
  1956. type: 'tv',
  1957. data: () => Array.from(document.querySelectorAll('script[type="text/template"]')).map(e => e.innerHTML.match(/parentTitle"\s*:\s*"(.+?)"/)).filter((x) => x != null)[0][1]
  1958. },
  1959. {
  1960. condition: () => document.querySelector('[data-automation-id=title]'),
  1961. type: 'movie',
  1962. data: () => document.querySelector('[data-automation-id=title]').textContent.trim().replace(/\[.{1,8}\]/, '')
  1963. }
  1964. ]
  1965. },
  1966. BoxOfficeMojo: {
  1967. host: ['boxofficemojo.com'],
  1968. condition: () => Always,
  1969. products: [
  1970. {
  1971. condition: () => document.location.pathname.startsWith('/release/'),
  1972. type: 'movie',
  1973. data: () => document.querySelector('meta[name=title]').content
  1974. },
  1975. {
  1976. // Old page design
  1977. condition: () => ~document.location.search.indexOf('id=') && document.querySelector('#body table:nth-child(2) tr:first-child b'),
  1978. type: 'movie',
  1979. data: () => document.querySelector('#body table:nth-child(2) tr:first-child b').firstChild.textContent
  1980. }]
  1981. },
  1982. AllMovie: {
  1983. host: ['allmovie.com'],
  1984. condition: () => document.querySelector('h2.movie-title'),
  1985. products: [{
  1986. condition: () => document.querySelector('h2.movie-title'),
  1987. type: 'movie',
  1988. data: () => document.querySelector('h2.movie-title').firstChild.textContent.trim()
  1989. }]
  1990. },
  1991. 'en.wikipedia': {
  1992. host: ['en.wikipedia.org'],
  1993. condition: Always,
  1994. products: [{
  1995. condition: function () {
  1996. if (!document.querySelector('.infobox .summary')) {
  1997. return false
  1998. }
  1999. const r = /\d\d\d\d films/
  2000. return $('#catlinks a').filter((i, e) => e.firstChild.textContent.match(r)).length
  2001. },
  2002. type: 'movie',
  2003. data: () => document.querySelector('.infobox .summary').firstChild.textContent
  2004. },
  2005. {
  2006. condition: function () {
  2007. if (!document.querySelector('.infobox .summary')) {
  2008. return false
  2009. }
  2010. const r = /television series/
  2011. return $('#catlinks a').filter((i, e) => e.firstChild.textContent.match(r)).length
  2012. },
  2013. type: 'tv',
  2014. data: () => document.querySelector('.infobox .summary').firstChild.textContent
  2015. }]
  2016. },
  2017. fandango: {
  2018. host: ['fandango.com'],
  2019. condition: () => document.querySelector("meta[property='og:title']"),
  2020. products: [{
  2021. condition: Always,
  2022. type: 'movie',
  2023. data: () => document.querySelector("meta[property='og:title']").content.match(/(.+?)\s+\(\d{4}\)/)[1].trim()
  2024. }]
  2025. },
  2026. flixster: {
  2027. host: ['www.flixster.com'],
  2028. condition: () => Always,
  2029. products: [{
  2030. condition: () => parseLDJSON('@type') === 'Movie',
  2031. type: 'movie',
  2032. data: () => parseLDJSON('name', (j) => (j['@type'] === 'Movie'))
  2033. }]
  2034. },
  2035. themoviedb: {
  2036. host: ['themoviedb.org'],
  2037. condition: () => document.querySelector("meta[property='og:type']"),
  2038. products: [{
  2039. condition: () => document.querySelector("meta[property='og:type']").content === 'movie',
  2040. type: 'movie',
  2041. data: () => document.querySelector("meta[property='og:title']").content
  2042. },
  2043. {
  2044. condition: () => document.querySelector("meta[property='og:type']").content === 'tv' || document.querySelector("meta[property='og:type']").content === 'tv_series',
  2045. type: 'tv',
  2046. data: () => document.querySelector("meta[property='og:title']").content
  2047. }]
  2048. },
  2049. letterboxd: {
  2050. host: ['letterboxd.com'],
  2051. condition: () => unsafeWindow.filmData && 'name' in unsafeWindow.filmData,
  2052. products: [{
  2053. condition: Always,
  2054. type: 'movie',
  2055. data: () => unsafeWindow.filmData.name
  2056. }]
  2057. },
  2058. TVmaze: {
  2059. host: ['tvmaze.com'],
  2060. condition: () => document.querySelector('h1'),
  2061. products: [{
  2062. condition: Always,
  2063. type: 'tv',
  2064. data: () => document.querySelector('h1').firstChild.textContent
  2065. }]
  2066. },
  2067. TVGuide: {
  2068. host: ['tvguide.com'],
  2069. condition: Always,
  2070. products: [{
  2071. condition: () => document.location.pathname.startsWith('/tvshows/'),
  2072. type: 'tv',
  2073. data: function () {
  2074. if (document.querySelector('meta[itemprop=name]')) {
  2075. return document.querySelector('meta[itemprop=name]').content
  2076. } else {
  2077. return document.querySelector("meta[property='og:title']").content.split('|')[0]
  2078. }
  2079. }
  2080. }]
  2081. },
  2082. followshows: {
  2083. host: ['followshows.com'],
  2084. condition: Always,
  2085. products: [{
  2086. condition: () => document.querySelector("meta[property='og:type']").content === 'video.tv_show',
  2087. type: 'tv',
  2088. data: () => document.querySelector("meta[property='og:title']").content
  2089. }]
  2090. },
  2091. TheTVDB: {
  2092. host: ['thetvdb.com'],
  2093. condition: Always,
  2094. products: [{
  2095. condition: () => document.location.pathname.startsWith('/series/'),
  2096. type: 'tv',
  2097. data: () => document.getElementById('series_title').firstChild.textContent.trim()
  2098. },
  2099. {
  2100. condition: () => document.location.pathname.startsWith('/movies/'),
  2101. type: 'movie',
  2102. data: () => document.getElementById('series_title').firstChild.textContent.trim()
  2103. }]
  2104. },
  2105. ConsequenceOfSound: {
  2106. host: ['consequence.net', 'consequenceofsound.net'],
  2107. condition: () => document.querySelector('#main-content .review-summary'),
  2108. products: [
  2109. {
  2110. condition: () => document.querySelector('meta[name="cXenseParse:cns-artist-names"]') && document.querySelector('em'),
  2111. type: 'music',
  2112. data: function () {
  2113. window.setInterval(function () {
  2114. if (document.getElementById('ot-sdk-btn-floating')) {
  2115. document.getElementById('ot-sdk-btn-floating').remove()
  2116. }
  2117. }, 5000)
  2118. const artist = document.querySelector('meta[name="cXenseParse:cns-artist-names"]').content
  2119. const arr = Array.from(document.querySelectorAll('em')).map((em) => em.textContent.trim())
  2120. const counts = {}
  2121. for (const num of arr) {
  2122. counts[num] = counts[num] ? counts[num] + 1 : 1
  2123. }
  2124. const max = Math.max(...Object.values(counts))
  2125. const maxIndex = Object.values(counts).indexOf(max)
  2126. const title = Object.keys(counts)[maxIndex]
  2127. return [artist, title]
  2128. }
  2129. },
  2130. {
  2131. condition: () => document.title.match(/'(.*?)'\s*Album/i) && document.querySelector('meta[name="cXenseParse:cns-artist-names"]'),
  2132. type: 'music',
  2133. data: function () {
  2134. window.setInterval(function () {
  2135. if (document.getElementById('ot-sdk-btn-floating')) {
  2136. document.getElementById('ot-sdk-btn-floating').remove()
  2137. }
  2138. }, 5000)
  2139. const title = document.title.match(/'(.*?)'\s*Album/i)[1]
  2140. const artist = document.querySelector('meta[name="cXenseParse:cns-artist-names"]').content
  2141. return [artist, title]
  2142. }
  2143. },
  2144. {
  2145. condition: () => document.title.match(/(.+?)\s+\u2013\s+(.+?) \| Album Review/),
  2146. type: 'music',
  2147. data: function () {
  2148. window.setInterval(function () {
  2149. if (document.getElementById('ot-sdk-btn-floating')) {
  2150. document.getElementById('ot-sdk-btn-floating').remove()
  2151. }
  2152. }, 5000)
  2153. const m = document.title.match(/(.+?)\s+\u2013\s+(.+?) \| Album Review/)
  2154. return [m[1], m[2]]
  2155. }
  2156. },
  2157. {
  2158. condition: () => document.location.pathname.indexOf('/album-review') !== -1 && document.querySelector('a.tag[href*="/artist/"'),
  2159. type: 'music',
  2160. data: function () {
  2161. window.setInterval(function () {
  2162. if (document.getElementById('ot-sdk-btn-floating')) {
  2163. document.getElementById('ot-sdk-btn-floating').remove()
  2164. }
  2165. }, 5000)
  2166. const artistAndTitleWithDash = document.location.pathname.match(/album-review-([\w-]+)/)[1]
  2167. const artistWithDash = document.querySelector('a.tag[href*="/artist/"').pathname.match(/artist\/([\w-]+)/)[1]
  2168. const titleWithDash = artistAndTitleWithDash.replace(artistWithDash, '')
  2169. const title = titleWithDash.replace('-', ' ').trim()
  2170. const artist = artistWithDash.replace('-', ' ').trim()
  2171. return [artist, title]
  2172. }
  2173. }]
  2174. },
  2175. Pitchfork: {
  2176. host: ['pitchfork.com'],
  2177. condition: () => ~document.location.href.indexOf('/reviews/albums/'),
  2178. products: [{
  2179. condition: () => document.querySelector('.single-album-tombstone'),
  2180. type: 'music',
  2181. data: function () {
  2182. let artist
  2183. let album
  2184. if (document.querySelector('.single-album-tombstone .artists')) {
  2185. artist = document.querySelector('.single-album-tombstone .artists').innerText.trim()
  2186. } else if (document.querySelector('.single-album-tombstone .artist-list')) {
  2187. artist = document.querySelector('.single-album-tombstone .artist-list').innerText.trim()
  2188. }
  2189. if (document.querySelector('.single-album-tombstone h1.review-title')) {
  2190. album = document.querySelector('.single-album-tombstone h1.review-title').innerText.trim()
  2191. } else if (document.querySelector('.single-album-tombstone h1')) {
  2192. album = document.querySelector('.single-album-tombstone h1').innerText.trim()
  2193. }
  2194.  
  2195. return [artist, album]
  2196. }
  2197. }]
  2198. },
  2199. 'Last.fm': {
  2200. host: ['last.fm'],
  2201. condition: () => document.querySelector('*[data-page-resource-type]') && document.querySelector('*[data-page-resource-type]').dataset.pageResourceType === 'album',
  2202. products: [{
  2203. condition: () => document.querySelector('*[data-page-resource-type]').dataset.pageResourceName,
  2204. type: 'music',
  2205. data: function () {
  2206. const artist = document.querySelector('*[data-page-resource-type]').dataset.pageResourceArtistName
  2207. const album = document.querySelector('*[data-page-resource-type]').dataset.pageResourceName
  2208. return [artist, album]
  2209. }
  2210. }]
  2211. },
  2212. TVNfo: {
  2213. host: ['tvnfo.com'],
  2214. condition: () => document.querySelector('.ui.breadcrumb a[href*="/series"]'),
  2215. products: [{
  2216. condition: Always,
  2217. type: 'tv',
  2218. data: function () {
  2219. const years = document.querySelector('#title h1 .years').textContent.trim()
  2220. const title = document.querySelector('#title h1').textContent.replace(years, '').trim()
  2221. return title
  2222. }
  2223. }]
  2224. },
  2225. rateyourmusic: {
  2226. host: ['rateyourmusic.com'],
  2227. condition: () => document.querySelector("meta[property='og:type']"),
  2228. products: [{
  2229. condition: () => document.querySelector("meta[property='og:type']").content === 'music.album',
  2230. type: 'music',
  2231. data: function () {
  2232. const artist = document.querySelector('.section_main_info .artist').innerText.trim()
  2233. const album = document.querySelector('.section_main_info .album_title').innerText.trim()
  2234. return [artist, album]
  2235. }
  2236. }]
  2237. },
  2238. spotify: {
  2239. host: ['open.spotify.com'],
  2240. condition: Always,
  2241. products: [{
  2242. condition: () => document.location.pathname.startsWith('/album/') && document.querySelector('.Root__main-view h1'),
  2243. type: 'music',
  2244. data: function () {
  2245. const album = document.querySelector('.Root__main-view h1').textContent.trim()
  2246. let artist = []
  2247. document.querySelector('.Root__main-view h1').parentNode.parentNode.parentNode.querySelectorAll('a[href*="/artist/"]').forEach(function (a) {
  2248. artist.push(a.textContent.trim())
  2249. })
  2250. artist = artist.join(' ')
  2251. return [artist, album]
  2252. }
  2253. }]
  2254. },
  2255. nme: {
  2256. host: ['nme.com'],
  2257. condition: () => document.location.pathname.startsWith('/reviews/'),
  2258. products: [
  2259. {
  2260. condition: () => document.querySelector('.tdb-breadcrumbs a[href*="/reviews/film-reviews"]'),
  2261. type: 'movie',
  2262. data: function () {
  2263. try {
  2264. return document.title.match(/[‘'](.+?)[’']/)[1]
  2265. } catch (e) {
  2266. try {
  2267. return document.querySelector('h1.tdb-title-text').textContent.match(/[‘'](.+?)[’']/)[1]
  2268. } catch (e) {
  2269. return document.querySelector('h1').textContent.match(/:\s*(.+)/)[1].trim()
  2270. }
  2271. }
  2272. }
  2273. },
  2274. {
  2275. condition: () => document.querySelector('#nme-music-header'),
  2276. type: 'music',
  2277. data: () => document.querySelector('h1.tdb-title-text').textContent.match(/\s*(.+?)\s*.\s*[‘'](.+?)[’']/).slice(1)
  2278. },
  2279. {
  2280. condition: () => document.querySelector('.tdb-breadcrumbs a[href*="/reviews/tv-reviews"]'),
  2281. type: 'tv',
  2282. data: () => document.querySelector('h1.tdb-title-text').textContent.match(/[‘'](.+?)[’']/)[1]
  2283. }]
  2284. },
  2285. albumoftheyear: {
  2286. host: ['albumoftheyear.org'],
  2287. condition: Always,
  2288. products: [{
  2289. condition: () => document.location.pathname.startsWith('/album/'),
  2290. type: 'music',
  2291. data: function () {
  2292. const artist = document.querySelector('*[itemprop=byArtist] *[itemprop=name]').textContent
  2293. const album = document.querySelector('.albumTitle *[itemprop=name]').textContent
  2294. return [artist, album]
  2295. }
  2296. }]
  2297. },
  2298. epguides: {
  2299. host: ['epguides.com'],
  2300. condition: () => document.getElementById('eplist'),
  2301. products: [{
  2302. condition: () => document.getElementById('eplist') && document.querySelector('.center.titleblock h2'),
  2303. type: 'tv',
  2304. data: () => document.querySelector('.center.titleblock h2').textContent.trim()
  2305. }]
  2306. },
  2307. ShareTV: {
  2308. host: ['sharetv.com'],
  2309. condition: () => document.location.pathname.startsWith('/shows/'),
  2310. products: [{
  2311. condition: () => document.location.pathname.split('/').length === 3 && document.querySelector("meta[property='og:title']"),
  2312. type: 'tv',
  2313. data: () => document.querySelector("meta[property='og:title']").content
  2314. }]
  2315. },
  2316. /*
  2317. netflix: {
  2318. host: ['netflix.com'],
  2319. condition: !(document.querySelector('.button-nfplayerPlay') || document.querySelector('.nf-big-play-pause') || document.querySelector('.AkiraPlayer video')),
  2320.  
  2321. // TODO
  2322. // https://www.netflix.com/de/title/70264888
  2323. // https://www.netflix.com/de/title/70178217
  2324. // https://www.netflix.com/de/title/70305892 ## Movie
  2325. // https://www.netflix.com/de-en/title/80108495 ## No meta
  2326.  
  2327. products: [{
  2328. condition: () => parseLDJSON('@type') === 'Movie',
  2329. type: 'movie',
  2330. data: () => parseLDJSON('name', (j) => (j['@type'] === 'Movie'))
  2331. },
  2332. {
  2333. condition: () => parseLDJSON('@type') === 'TVSeries',
  2334. type: 'tv',
  2335. data: () => parseLDJSON('name', (j) => (j['@type'] === 'TVSeries'))
  2336. }]
  2337. },
  2338. */
  2339. ComedyCentral: {
  2340. host: ['cc.com'],
  2341. condition: () => document.location.pathname.startsWith('/shows/'),
  2342. products: [{
  2343. condition: () => document.location.pathname.split('/').length === 3 && document.querySelector("meta[property='og:title']"),
  2344. type: 'tv',
  2345. data: () => document.querySelector("meta[property='og:title']").content.replace('| Comedy Central', '').trim()
  2346. },
  2347. {
  2348. condition: () => document.location.pathname.split('/').length === 3 && document.title.match(/(.+?)\s+-\s+Series/),
  2349. type: 'tv',
  2350. data: () => document.title.match(/(.+?)\s+-\s+Series/)[1]
  2351. }]
  2352. },
  2353. TVHoard: {
  2354. host: ['tvhoard.com'],
  2355. condition: Always,
  2356. products: [{
  2357. condition: () => document.location.pathname.split('/').length === 3 && document.location.pathname.split('/')[1] === 'titles' && !document.querySelector('app-root title-secondary-details-panel .seasons') && document.querySelector('app-root title-page-container h1.title a'),
  2358. type: 'movie',
  2359. data: () => document.querySelector('app-root title-page-container h1.title a').textContent.trim()
  2360. },
  2361. {
  2362. condition: () => document.location.pathname.split('/').length === 3 && document.location.pathname.split('/')[1] === 'titles' && document.querySelector('app-root title-secondary-details-panel .seasons') && document.querySelector('app-root title-page-container h1.title a'),
  2363. type: 'tv',
  2364. data: () => document.querySelector('app-root title-page-container h1.title a').textContent.trim()
  2365. }]
  2366. },
  2367. AMC: {
  2368. host: ['amc.com'],
  2369. condition: () => document.location.pathname.startsWith('/shows/'),
  2370. products: [
  2371. {
  2372. condition: () => document.querySelector('.feeds[itemtype="http://schema.org/TVSeries"] h1'),
  2373. type: 'tv',
  2374. data: () => document.querySelector('.feeds[itemtype="http://schema.org/TVSeries"] h1').textContent
  2375. },
  2376. {
  2377. condition: () => document.location.pathname.split('/').length === 3 && document.querySelector("meta[property='og:type']") && document.querySelector("meta[property='og:type']").content.indexOf('tv_show') !== -1,
  2378. type: 'tv',
  2379. data: () => document.querySelector('.video-card-description h1').textContent.trim()
  2380. }]
  2381. },
  2382. AMCplus: {
  2383. host: ['amcplus.com'],
  2384. condition: () => Always,
  2385. products: [
  2386. {
  2387. condition: () => document.title.match(/Watch .+? |/),
  2388. type: 'tv',
  2389. data: () => document.title.match(/Watch (.+?) |/)[1].trim()
  2390. }]
  2391. },
  2392. RlsBB: {
  2393. host: ['rlsbb.ru'],
  2394. condition: () => document.querySelectorAll('.post').length === 1,
  2395. products: [
  2396. {
  2397. condition: () => document.querySelector('#post-wrapper .entry-meta a[href*="/category/movies/"]'),
  2398. type: 'movie',
  2399. data: () => document.querySelector('h1.entry-title').textContent.match(/(.+?)\s+\d{4}/)[1].trim()
  2400. },
  2401. {
  2402. condition: () => document.querySelector('#post-wrapper .entry-meta a[href*="/category/tv-shows/"]'),
  2403. type: 'tv',
  2404. data: () => document.querySelector('h1.entry-title').textContent.match(/(.+?)\s+S\d{2}/)[1].trim()
  2405. }]
  2406. },
  2407. newalbumreleases: {
  2408. host: ['newalbumreleases.net'],
  2409. condition: () => document.querySelectorAll('#content .single').length === 1,
  2410. products: [
  2411. {
  2412. condition: () => document.querySelector('#content .single .cover .entry'),
  2413. type: 'music',
  2414. data: function () {
  2415. const mArtist = document.querySelector('#content .single .cover .entry').textContent.match(/Artist.\s*(.+)\s+/i)
  2416. if (mArtist) {
  2417. const mAlbum = document.querySelector('#content .single .cover .entry').textContent.match(/Album.\s*(.+)\s+/i)
  2418. if (mAlbum) {
  2419. return [mArtist[1], mAlbum[1]]
  2420. }
  2421. }
  2422. }
  2423. }]
  2424. },
  2425. showtime: {
  2426. host: ['sho.com'],
  2427. condition: Always,
  2428. products: [
  2429. {
  2430. condition: () => parseLDJSON('@type') === 'Movie',
  2431. type: 'movie',
  2432. data: () => parseLDJSON('name', (j) => (j['@type'] === 'Movie'))
  2433. },
  2434. {
  2435. condition: () => parseLDJSON('@type') === 'TVSeries',
  2436. type: 'tv',
  2437. data: () => parseLDJSON('name', (j) => (j['@type'] === 'TVSeries'))
  2438. }]
  2439. },
  2440. epicgames: {
  2441. host: ['www.epicgames.com', 'store.epicgames.com'],
  2442. condition: () => document.querySelector('div[data-component="PDPTitleHeader"]'),
  2443. products: [{
  2444. condition: Always,
  2445. type: 'pcgame',
  2446. data: () => document.querySelector('div[data-component="PDPTitleHeader"]').firstElementChild.textContent
  2447. }]
  2448. },
  2449. gog: {
  2450. host: ['www.gog.com'],
  2451. condition: () => document.querySelector('.productcard-basics__title'),
  2452. products: [
  2453. {
  2454. condition: () => document.location.pathname.slice(1, 5) === 'game',
  2455. type: 'pcgame',
  2456. data: () => document.querySelector('.productcard-basics__title').textContent
  2457. },
  2458. {
  2459. condition: () => document.location.pathname.slice(1, 6) === 'movie',
  2460. type: 'movie',
  2461. data: () => document.querySelector('.productcard-basics__title').textContent
  2462. }
  2463. ]
  2464. },
  2465. allmusic: {
  2466. host: ['allmusic.com'],
  2467. condition: Always,
  2468. products: [{
  2469. condition: () => document.location.pathname.indexOf('/album/') !== -1,
  2470. type: 'music',
  2471. data: function () {
  2472. const ld = parseLDJSON(['name', 'byArtist'], (j) => (j['@type'] === 'MusicAlbum'))
  2473. const album = ld[0]
  2474. const artist = 'name' in ld[1] ? ld[1].name : ld[1].map(x => x.name).join(' ')
  2475. return [artist, album]
  2476. }
  2477. }]
  2478. }
  2479.  
  2480. }
  2481.  
  2482. async function main () {
  2483. let dataFound = false
  2484.  
  2485. let map = false
  2486.  
  2487. for (const name in sites) {
  2488. const site = sites[name]
  2489. if (site.host.some(function (e) { return ~this.indexOf(e) }, document.location.hostname) && site.condition()) {
  2490. for (let i = 0; i < site.products.length; i++) {
  2491. if (site.products[i].condition()) {
  2492. // Check map for a match
  2493. if (map === false) {
  2494. map = JSON.parse(await GM.getValue('map', '{}'))
  2495. }
  2496. const docurl = filterUniversalUrl(document.location.href)
  2497. if (docurl in map) {
  2498. // Found in map, show result
  2499. const metaurl = map[docurl]
  2500. metacritic_general_product_setup()
  2501. metacritic.mapped.apply(undefined, [docurl, site.products[i], absoluteMetaURL(metaurl), site.products[i].type])
  2502. dataFound = true
  2503. break
  2504. }
  2505. // Try to retrieve item name from page
  2506. let data
  2507. try {
  2508. data = site.products[i].data()
  2509. } catch (e) {
  2510. data = false
  2511. console.error(`ShowMetacriticRatings: Error in data() of site='${name}', type='${site.products[i].type}'`)
  2512. console.error(e)
  2513. }
  2514. if (data) {
  2515. const params = [docurl, site.products[i]]
  2516. if (Array.isArray(data)) {
  2517. params.push(...data)
  2518. } else {
  2519. params.push(data)
  2520. }
  2521. metacritic_general_product_setup()
  2522. metacritic[site.products[i].type].apply(undefined, params)
  2523. dataFound = true
  2524. }
  2525. break
  2526. }
  2527. }
  2528. break
  2529. }
  2530. }
  2531. return dataFound
  2532. }
  2533.  
  2534. (async function () {
  2535. const gdpr = await acceptGDPR()
  2536. if (!gdpr) {
  2537. GM.registerMenuCommand('Show Metacritic.com ratings - Accept terms of service', () => acceptGDPR(true).then((yes) => yes && document.location.reload()))
  2538. return
  2539. }
  2540. await versionUpdate()
  2541. const firstRunResult = await main()
  2542.  
  2543. GM.registerMenuCommand('Show Metacritic.com ratings - Search now', () => openSearchBox())
  2544.  
  2545. let lastLoc = document.location.href
  2546. let lastContent = document.body.innerText
  2547. let lastCounter = 0
  2548. async function newpage () {
  2549. if (lastContent === document.body.innerText && lastCounter < 15) {
  2550. window.setTimeout(newpage, 500)
  2551. lastCounter++
  2552. } else {
  2553. lastContent = document.body.innerText
  2554. lastCounter = 0
  2555. const re = await main()
  2556. if (!re) { // No page matched or no data found
  2557. window.setTimeout(newpage, 1000)
  2558. }
  2559. }
  2560. }
  2561. window.setInterval(function () {
  2562. if (document.location.href !== lastLoc) {
  2563. lastLoc = document.location.href
  2564. $('#mcdiv123').remove()
  2565.  
  2566. window.setTimeout(newpage, 1000)
  2567. }
  2568. }, 500)
  2569.  
  2570. if (!firstRunResult) {
  2571. // Initial run had no match, let's try again there may be new content
  2572. window.setTimeout(main, 2000)
  2573. }
  2574. })()