Greasy Fork

trakt.tv pseudo-flix.pro, Braflix integration

Adds pseudo-flix.pro and Braflix buttons to the overview page of shows and movies

目前为 2024-08-08 提交的版本。查看 最新版本

// ==UserScript==
// @name        trakt.tv pseudo-flix.pro, Braflix integration
// @match       https://trakt.tv/movies/*
// @match       https://trakt.tv/shows/*
// @grant       none
// @version     1.1.0
// @license     GPLv3
// @icon        https://icons.duckduckgo.com/ip2/trakt.tv.ico
// @description Adds pseudo-flix.pro and Braflix buttons to the overview page of shows and movies
// @run-at      document-end
// @namespace https://greasyfork.org/users/1257939
// ==/UserScript==

(function() {
    const createExternalLink = () => {
        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 buttonsPath = document.querySelector('.external > li');

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

        const showMovie = location.pathname.split("/")[1] === "movies" ? "movie" : "tv";
        const linkElementMovieWeb = createNewLinkElement("pseudo-flix", `media/tmdb-${showMovie}-${tmdbId}-${title}`);
        const linkElementBraflix = createNewLinkElement("braflix", `${showMovie}/${tmdbId}/${season}/${episode}?play=true`);

        buttonsPath.appendChild(linkElementMovieWeb);
        buttonsPath.appendChild(linkElementBraflix);
    };

    const extractDetailsFromUrl = (url) => {
        const parts = url.split("/");
        return {
            tmdbId: parts[4],
            season: parts[6],
            episode: parts[8]
        };
    };

    const sanitizeTitle = (title) => {
        return title.replace(/-\d{4}$/, ''); // Removes year from URL
    };

    const createNewLinkElement = (service, suffix) => {
        const linkElement = document.createElement('a');
        linkElement.target = "_blank";
        linkElement.id = `external-link-${service}`;
        linkElement.href = `https://${service === 'pseudo-flix' ? 'pseudo-flix.pro' : 'www.braflix.video/de'}/${suffix}`;
        linkElement.dataset.originalTitle = "";
        linkElement.title = "";
        linkElement.textContent = service === 'braflix' ? 'Braflix' : 'pseudo-flix';
        return linkElement;
    };

    createExternalLink();
})();