Greasy Fork

trakt.tv movie-web.app integration

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

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

// ==UserScript==
// @name        trakt.tv movie-web.app integration
// @match       https://trakt.tv/movies/*
// @match       https://trakt.tv/shows/*
// @grant       none
// @version     0.0.1
// @icon        https://icons.duckduckgo.com/ip2/trakt.tv.ico
// @license     GPLv3
// @description Adds a movie-web.app button to the overview page of shows and movies
// @run-at      document-end
// @namespace https://greasyfork.org/users/1257939
// ==/UserScript==

(function() {
	let tmdbLink = document.getElementById("external-link-tmdb");
	if (!tmdbLink) {
		console.error("TMDB link doesn’t exist.")
		return; // Ensure the TMDB link exists before proceeding
	}

	let tmdbId = tmdbLink.href.split("/")[4];
	let title = location.pathname.split("/")[2].replace(/-\d{4}$/, ''); // Remove trailing year from the title
	let buttonsPath = document.querySelector('.external > li');

	if (!buttonsPath) {
		console.error("Path for buttons doesn’t exist.")
		return; // Ensure the path for buttons exists before proceeding
	}

    let linkElement = document.createElement('a');
    linkElement.target = "_blank";
    linkElement.id = "external-link-movie-web";
    let showMovie = location.pathname.split("/")[1] === "movies" ? "movie" : "tv";
    linkElement.href = "https://movie-web.app/media/tmdb-" + showMovie + "-" + tmdbId + "-" + title;
    linkElement.dataset.originalTitle = "";
    linkElement.title = "";
    linkElement.textContent = "movie-web";
    buttonsPath.appendChild(linkElement);
})();