Filmweb External Ratings

Add IMDb, Rotten Tomatoes and Metacritic ratings to Filmweb

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Filmweb External Ratings
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Add IMDb, Rotten Tomatoes and Metacritic ratings to Filmweb
// @author       mrkkr
// @match        http*://www.filmweb.pl/serial/*
// @match        http*://www.filmweb.pl/film/*
// @match        http*://www.filmweb.pl/tvshow/*
// @grant        GM_xmlhttpRequest 
// @grant        GM.xmlHttpRequest
// @grant        GM_addStyle
// @connect      omdbapi.comlingerie
// @connect      www.imdb.com
// @connect      www.rottentomatoes.com
// @connect      www.metacritic.com
// ==/UserScript==

(function() {
    'use strict';

    const ICONS = {
        imdb: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjwhRE9DVFlQRSBzdmcgIFBVQkxJQyAnLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4nICAnaHR0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+7B/tWBuL3OYsFQAAAABJRU5ErkJggg==',
        metacritic: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAAADFBMVEUAAAACIzD/ygD///+DWqJTAAAAAXRSTlMAQObYZgAAAVFJREFUOMuNk0uOgzAQREcsc5Tcx0HKhj13iOAS7Nkgge/DUby0PFWuTnuG0Uhp5SO/UM8daH99Wl2M82X9m0TW3ta3WGt1cI9HCLykGQJKFiUWgodnGGCN+zuxCDyRUSJYWeZeE0NCxsBGUAoyklTFUErCPnIGgQzJTGdVTIWZsQIpUCetzUnJs4JFgJLH/t6kLwnEQKjgHCiJDeBVEkF3qAtqMhoBUBf6GAkYIKAE4GbgrBKCjb8RBAB0RjCxTX6dP0DmhcEBCqrsIA9Vkgy8plTbRAngV6Syg54AGQc1T9qAdWXgkFAS/Tl11QD7qjfRgSR460nFYBKs7Z5K8nKwSKKp0oOiRGAn2EwSNCBoVRLWuGocJFEbGhhJ1Aa3ocQ3AaAky+ljOSUfZVgpkWL10e6lmC/DD6ck1+PR6ZKRCcuAYB3/HkIvgX8Psh/1D+sbAAmSjR+xz1QAAAAASUVORK5CYII='
    };

    const OMDB_API_KEY = '9dd3bf83';

    async function addRatingsToPage(data) {
        let ratingsContainer = document.querySelector('.filmRating__ratingData');
        if (!ratingsContainer) {
            const filmInfo = document.querySelector('.filmInfo');
            if (!filmInfo) return;

            ratingsContainer = document.createElement('div');
            ratingsContainer.className = 'filmRating__ratingData';
            filmInfo.appendChild(ratingsContainer);
        }

        const externalRatings = document.createElement('div');
        externalRatings.className = 'filmRating__externalRatings';
        externalRatings.style.cssText = `
            margin-top: 20px;
            padding: 15px 0;
            background: rgba(0,0,0,0.03);
            border-radius: 4px;
        `;

        const header = document.createElement('h3');
        header.textContent = 'External Ratings';
        header.style.cssText = 'font-size: 16px; margin-bottom: 15px; color: #333;';
        externalRatings.appendChild(header);

        data.Ratings.forEach(rating => {
            let icon, label, url;
            switch(rating.Source) {
                case 'Internet Movie Database':
                    icon = ICONS.imdb;
                    label = 'IMDb';
                    url = `https://www.imdb.com/title/${data.imdbID}/`;
                    break;
                case 'Rotten Tomatoes':
                    icon = ICONS.rotten;
                    label = 'Rotten Tomatoes';
                    url = `https://www.rottentomatoes.com/m/${data.Title.toLowerCase().replace(/[^a-z0-9]/g, '_')}_${data.Year}`;
                    break;
                case 'Metacritic':
                    icon = ICONS.metacritic;
                    label = 'Metacritic';
                    url = `https://www.metacritic.com/movie/${data.Title.toLowerCase().replace(/[^a-z0-9]/g, '-')}`;
                    break;
            }

            const ratingDiv = document.createElement('div');
            ratingDiv.style.cssText = `
                display: flex;
                align-items: center;
                margin: 10px 0;
                padding: 0;
                background: white;
                border-radius: 4px;
                cursor: pointer;
            `;

            ratingDiv.innerHTML = `
                <img src="${icon}" style="width: 16px; height: 16px; margin-right: 8px;">
                <span style="font-weight: bold; min-width: 80px; margin-right: 8px;">${label}</span>
                <span style="color: #333;">${rating.Value}</span>
            `;

            ratingDiv.addEventListener('click', () => window.open(url, '_blank'));
            externalRatings.appendChild(ratingDiv);
        });

        ratingsContainer.appendChild(externalRatings);
    }

    async function getRatings(title, year) {
        return new Promise((resolve, reject) => {
            GM_xmlhttpRequest({
                method: 'GET',
                url: `https://www.omdbapi.com/?apikey=${OMDB_API_KEY}&t=${encodeURIComponent(title)}&y=${year}`,
                headers: {
                    'Accept': 'application/json'
                },
                onload: function(response) {
                    try {
                        const data = JSON.parse(response.responseText);
                        console.log('OMDB Response:', data);
                        if (data.Response === 'True') {
                            resolve(data);
                        } else {
                            reject(new Error(data.Error));
                        }
                    } catch (e) {
                        reject(e);
                    }
                },
                onerror: function(error) {
                    console.error('OMDB Request failed:', error);
                    reject(error);
                }
            });
        });
    }

    async function init() {
        console.log('Initializing ratings script...');

        while (!document.querySelector('.filmCoverSection__title')) {
            await new Promise(r => setTimeout(r, 100));
        }

        const originalTitle = document.querySelector('.filmCoverSection__originalTitle')?.firstChild?.textContent?.trim();
        const localTitle = document.querySelector('.filmCoverSection__title')?.textContent?.trim();
        const year = document.querySelector('.filmCoverSection__year')?.textContent?.trim() || '';
        const title = originalTitle || localTitle;

        console.log('Movie info:', {title, year});

        try {
            const data = await getRatings(title, year);
            if (data?.Ratings?.length > 0) {
                await addRatingsToPage(data);
            } else {
                console.log('No ratings found');
            }
        } catch (error) {
            console.error('Error getting ratings:', error);
        }
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();