// ==UserScript== // @name trakt.tv sudo-flix.lol, Braflix integration // @match https://trakt.tv/movies/* // @match https://trakt.tv/shows/* // @grant none // @version 1.0.0 // @license GPLv3 // @icon https://icons.duckduckgo.com/ip2/trakt.tv.ico // @description Adds a sudo-flix.lol and Braflix buttons to the overview page of shows and movies // @run-at document-end // @namespace https://greasyfork.org/users/1257939 // @downloadURL none // ==/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("sudo-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 === 'sudo-flix' ? 'sudo-flix.lol' : 'www.braflix.video/de'}/${suffix}`; linkElement.dataset.originalTitle = ""; linkElement.title = ""; linkElement.textContent = service === 'braflix' ? 'Braflix' : 'sudo-flix'; return linkElement; }; createExternalLink(); })();