Greasy Fork

来自缓存

Greasy Fork is available in English.

filmweb.pl — Ratings from other websites

Show ratings on the filmweb.pl movie page from IMDB, Rotten Tomatoes and Metacritic.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         filmweb.pl — Ratings from other websites
// @description  Show ratings on the filmweb.pl movie page from IMDB, Rotten Tomatoes and Metacritic.
// @author       Rafal Enden
// @namespace    https://github.com/rafenden
// @homepageURL  https://github.com/rafenden/userscripts/blob/master/filmweb-ratings-from-other-websites
// @supportURL   https://github.com/rafenden/userscripts/issues
// @license      MIT
// @version      1.0.1
// @match        *://www.filmweb.pl/*
// @connect      www.omdbapi.com
// @grant        GM_xmlhttpRequest
// ==/UserScript==

// Show critics rating.
document.querySelector('.filmRating.hide').classList.remove('hide')

const getTitle = () => {
  return (document.querySelector('.filmCoverSection__originalTitle') || document.querySelector('.filmCoverSection__title')).textContent
}

const getYear = () => {
  return document.querySelector('.filmCoverSection__year').textContent
}

const addRatings = (json) => {
  const ratingsContainer = document.querySelector('.filmCoverSection__ratings')
  ratingsContainer.innerHTML = ratingsContainer.innerHTML + '<br />'

  for (let i = 0; i < json.Ratings.length; i++) {
    const rating = json.Ratings[i]
    let ratingUrl

    if (rating.Source === 'Rotten Tomatoes' && json.tomatoURL && json.tomatoURL !== 'N/A') {
      ratingUrl = json.tomatoURL
    }
    else if (rating.Source === 'Metacritic') {
      ratingUrl = `https://www.metacritic.com/search/all/${json.Title}/results`
    }
    else if (rating.Source === 'Internet Movie Database') {
      ratingUrl = `https://www.imdb.com/title/${json.imdbID}/`
    }

    ratingsContainer.innerHTML = ratingsContainer.innerHTML + `<a class="filmRating__count" style="margin-right: 10px" href="${ratingUrl}">${rating.Source}: <strong>${rating.Value}</strong></a>`
  }
}

// Fetch ratings from other websites.
GM_xmlhttpRequest({
  method: 'GET',
  url: `http://www.omdbapi.com/?apikey=6be019fc&tomatoes=true&t=${getTitle()}&y=${getYear()}`,
  onload: (response) => {
    const json = JSON.parse(response.responseText)
    if (json) {
      if (json.Error) {
        console.error(`Error: ${json.Error}`)
      }
      else {
        addRatings(json)
      }
    }
    else {
      console.error('Unknown error')
    }
  }
})