Trakt to Jellyseerr

Add a button to search Trakt shows/movies on Jellyseerr

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Trakt to Jellyseerr
// @namespace    https://trakt.tv/
// @icon         https://docs.jellyseerr.dev/img/favicon.ico
// @version      1.0
// @description  Add a button to search Trakt shows/movies on Jellyseerr
// @author       Undefined42
// @license MIT
// @match        https://trakt.tv/shows/*
// @match        https://trakt.tv/movies/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // FIXME: Replace with your Jellyseerr URL
    const jellyseerrUrl = 'https://jellyseerr.example.org';

    // Function to create and add the button
    function addJellyseerrButton() {
        const jellyseerrButton = document.createElement('button');
        jellyseerrButton.textContent = 'Search on Jellyseerr';
        jellyseerrButton.style.cssText = `
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 9999;
            padding: 10px 15px;
            background-color: #4f46e5cc;
            color: white;
            border: 0.8px solid #6366f1;
            border-radius: 6px;
            cursor: pointer;
            font-weight: bold;
        `;

        jellyseerrButton.addEventListener('click', searchOnJellyseerr);
        document.body.appendChild(jellyseerrButton);
    }

    // Function to search on Jellyseerr
    function searchOnJellyseerr() {
        const { tmdbId, mediaType } = getTmdbIdAndType();
        if (!tmdbId) {
            alert('TMDB ID not found');
            return;
        }

        const jellyseerrSearchUrl = `${jellyseerrUrl}/${mediaType}/${tmdbId}`;
        window.open(jellyseerrSearchUrl, '_blank');
    }

    // Function to get TMDB ID and media type from the page
    function getTmdbIdAndType() {
        const tmdbLink = document.querySelector('a[href^="https://www.themoviedb.org/"]');
        if (!tmdbLink) return { tmdbId: null, mediaType: null };

        const tmdbUrl = tmdbLink.href;
        const urlParts = tmdbUrl.split('/');

        let tmdbId, mediaType;

        if (urlParts.includes('movie')) {
            mediaType = 'movie';
            tmdbId = urlParts[urlParts.indexOf('movie') + 1];
        } else if (urlParts.includes('tv')) {
            mediaType = 'tv';
            tmdbId = urlParts[urlParts.indexOf('tv') + 1];
        } else {
            return { tmdbId: null, mediaType: null };
        }

        return { tmdbId, mediaType };
    }

    // Run the script
    addJellyseerrButton();
})();