// ==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 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("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(); })();