Greasy Fork

Greasy Fork is available in English.

trakt.tv movie-web.app, Braflix integration

Adds a movie-web.app and Braflix buttons to the overview page of shows and movies

当前为 2024-04-15 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        trakt.tv movie-web.app, Braflix integration
// @match       https://trakt.tv/movies/*
// @match       https://trakt.tv/shows/*
// @grant       none
// @version     0.1.2
// @icon        https://icons.duckduckgo.com/ip2/trakt.tv.ico
// @license     GPLv3
// @description Adds a movie-web.app and Braflix buttons to the overview page of shows and movies
// @run-at      document-end
// @namespace http://greasyfork.icu/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("movie-web", `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 === 'movie-web' ? 'mw.lonelil.ru' : 'www.braflix.video/de'}/${suffix}`;
        linkElement.dataset.originalTitle = "";
        linkElement.title = "";
        linkElement.textContent = service === 'braflix' ? 'Braflix' : 'movie-web';
        return linkElement;
    };

    createExternalLink();
})();