TMDB_check/TMDB_checker.user.js
2025-04-26 11:14:28 +00:00

87 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==UserScript==
// @name Vérificateur de disponibilité TMDB sur UNFR
// @namespace https://unfr.pw
// @version 1.8
// @description Vérifie si un film ou une série est disponible sur UNFR et ajoute le lien sur le site TMDB, sans clé API et avec une icône personnalisable facilement.
// @author Vous
// @match https://www.themoviedb.org/*
// @grant none
// @icon https://unfr.pw/favicon/apple-icon-72x72.png
// @downloadURL
// @updateURL
// ==/UserScript==
(function () {
'use strict';
const ICON_URL = 'https://unfr.pw/favicon/apple-icon-72x72.png'; // <-- Utilise l'@icon défini ci-dessus
// Attendre que lélément du titre soit chargé dans le DOM
function attendreTitre(callback) {
const intervalle = setInterval(() => {
const correspondance = window.location.pathname.match(/\/(movie|tv)\/(\d+)/);
const titre = document.querySelector('h2 a[href*="/movie/"], h2 a[href*="/tv/"]');
if (correspondance && titre) {
clearInterval(intervalle);
callback(correspondance[1], correspondance[2], titre);
}
}, 500);
}
// Vérifie la disponibilité via le nouvel endpoint
function verifierDisponibilite(type, tmdbId, callback) {
const url = `https://unfr.pw/check_tmdb?check=${tmdbId}&type=${type}`;
fetch(url)
.then(response => response.json())
.then(data => {
const disponible = data.code === 1;
const message = data.Explain || 'Indisponible';
callback(disponible, message);
})
.catch(() => {
callback(false, 'Erreur lors de la vérification');
});
}
// Ajoute le bouton à la page
function ajouterBouton(titre, disponible, message, tmdbId, type) {
const bouton = document.createElement('a');
bouton.textContent = disponible ? 'Disponible' : 'Faire une requête';
bouton.title = message;
const icone = document.createElement('img');
icone.src = ICON_URL;
icone.style.width = '16px';
icone.style.height = '16px';
icone.style.verticalAlign = 'middle';
icone.style.marginRight = '6px';
bouton.prepend(icone);
const paramId = type === 'tv' ? 'tvid' : 'movieid';
const urlBase = `https://unfr.pw/?d=fiche&${paramId}=${tmdbId}`;
bouton.href = disponible ? urlBase : urlBase + '#requete';
bouton.target = '_blank';
bouton.style.marginLeft = '10px';
bouton.style.padding = '4px 8px';
bouton.style.borderRadius = '6px';
bouton.style.fontSize = '0.9rem';
bouton.style.color = 'white';
bouton.style.backgroundColor = disponible ? 'green' : 'red';
bouton.style.textDecoration = 'none';
bouton.style.display = 'inline-flex';
bouton.style.alignItems = 'center';
titre.parentNode.appendChild(bouton);
}
// Lance l'exécution
attendreTitre((type, tmdbId, titre) => {
verifierDisponibilite(type, tmdbId, (disponible, message) => {
ajouterBouton(titre, disponible, message, tmdbId, type);
});
});
})();