Greasy Fork

Greasy Fork is available in English.

trakt.tv Vid Binge, BrocoFlix, Freek, Wovie integration

Adds Vid Binge, BrocoFlix, Freek, and Wovie buttons to the overview page of shows and movies

当前为 2024-12-07 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        trakt.tv Vid Binge, BrocoFlix, Freek, Wovie integration
// @match       https://trakt.tv/movies/*
// @match       https://trakt.tv/shows/*
// @grant       none
// @version     1.5.0
// @license     GPLv3
// @icon        https://icons.duckduckgo.com/ip2/trakt.tv.ico
// @description Adds Vid Binge, BrocoFlix, Freek, and Wovie buttons to the overview page of shows and movies
// @run-at      document-end
// @namespace   http://greasyfork.icu/users/1257939
// ==/UserScript==

(function() {
    // Extract and sanitize URL details
    const extractDetailsFromUrl = (url) => {
        try {
            const parts = url.split("/");
            return {
                tmdbId: parts[4],
                season: parts[6] || 1, // Default to first season on show overview page
                episode: parts[8] || 1, // Default to first episode on season overview page
            };
        } catch (error) {
            console.error("Failed to extract URL details:", error);
            return null;
        }
    };

    // Sanitize the title by removing year suffix if present
    const sanitizeTitle = (title) => {
        try {
            return title.replace(/-\d{4}$/, '');
        } catch (error) {
            console.error("Failed to sanitize title:", error);
            return title;
        }
    };

    // Create a new link element with appropriate attributes
    const createNewLinkElement = (service, suffix, targetUrl, textContent) => {
        try {
            const linkElement = document.createElement('a');
            linkElement.target = "_blank";
            linkElement.id = `external-link-${service}`;
            linkElement.href = `${targetUrl}/${suffix}`;
            linkElement.dataset.originalTitle = "";
            linkElement.title = "";
			linkElement.textContent = textContent;
            return linkElement;
        } catch (error) {
            console.error("Failed to create new link element:", error);
            return null;
        }
    };

    // Create external links based on the extracted details
    const createExternalLink = () => {
        try {
            const tmdbLink = document.getElementById("external-link-tmdb");
            if (!tmdbLink) {
                console.error("TMDB link doesn’t exist.");
                return;
            }

            const { tmdbId, season, episode } = extractDetailsFromUrl(tmdbLink.href);
            const title = sanitizeTitle(location.pathname.split("/")[2]); // Extract title from location
            const showMovie = location.pathname.split("/")[1] === "movies" ? "movie" : "tv";
            const buttonsPath = document.querySelector('.external > li');

            if (!buttonsPath) {
                console.error("Path for buttons doesn’t exist.");
                return;
            }

            const linkElementVidBinge = createNewLinkElement(
                'Vid Binge',
                `media/tmdb-${showMovie}-${tmdbId}-${title}`,
                'https://www.vidbinge.com',
                'Vid Binge'
            );

            const linkElementBrocoFlix = createNewLinkElement(
                'brocoFlix',
                `pages/info?id=${tmdbId}&type=${showMovie}`,
                'https://brocoflix.com',
                'BrocoFlix'
            );

            const linkElementFreek = createNewLinkElement(
                'freek',
                `watch/${showMovie}/${tmdbId}${showMovie === 'tv' ? `?season=${season}&ep=${episode}` : ''}`,
                'https://freek.to',
                'Freek'
            );

			const linkElementWovie = createNewLinkElement(
				'wovie',
				`play/${showMovie}/${tmdbId}/${title}${showMovie === 'tv' ? `?season=${season}&episode=${episode}` : ''}`,
				'https://wovie.vercel.app',
				'Wovie'
			);

            // Append the created links to the buttonsPath
            if (linkElementVidBinge) {
                buttonsPath.appendChild(linkElementVidBinge);
            }
            if (linkElementBrocoFlix) {
                buttonsPath.appendChild(linkElementBrocoFlix);
            }
            if (linkElementFreek) {
                buttonsPath.appendChild(linkElementFreek);
            }
            if (linkElementWovie) {
                buttonsPath.appendChild(linkElementWovie);
            }
        } catch (error) {
            console.error("Failed to create external links:", error);
        }
    };

    // Initialize the function when the page loads
    window.addEventListener('load', () => {
        createExternalLink();
    });
})();