Greasy Fork is available in English.
Ajoute automatiquement une image d'affiche à partir du titre de l'émission depuis IMDb.
当前为
// ==UserScript==
// @name Crunchyroll VF affiche depuis IMDb
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Ajoute automatiquement une image d'affiche à partir du titre de l'émission depuis IMDb.
// @author MASTERD
// @match https://www.crunchyroll.com/fr/news/guides/2022/3/4/crunchyroll-vf-anime
// @icon https://www.google.com/s2/favicons?sz=64&domain=crunchyroll.com
// @grant GM_xmlhttpRequest
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js
// ==/UserScript==
(async function() {
'use strict';
// Pour obtenir une clé API OMDB "https://www.omdbapi.com/apikey.aspx"
const omdbApiKey = '********'; // Remplacez ceci ******** par votre propre clé API OMDB
// Fonction pour trouver l'ID IMDb à partir du titre
const findIMDbId = async function(title) {
return new Promise((resolve, reject) => {
const url = `http://www.omdbapi.com/?t=${title}&apikey=${omdbApiKey}`;
GM_xmlhttpRequest({
method: "GET",
url: url,
onload: function(response) {
const data = JSON.parse(response.responseText);
if (data.Response === 'False') {
resolve('False');
} else {
resolve(data.imdbID);
}
},
onerror: function(error) {
reject(new Error(error));
}
});
});
};
// Fonction pour obtenir les détails du film à partir de l'ID IMDb
const getMovieDetails = async function(imdbId) {
return new Promise((resolve, reject) => {
const url = `http://www.omdbapi.com/?i=${imdbId}&apikey=${omdbApiKey}`;
GM_xmlhttpRequest({
method: "GET",
url: url,
onload: function(response) {
const data = JSON.parse(response.responseText);
resolve(data);
},
onerror: function(error) {
reject(new Error(error));
}
});
});
};
// Fonction pour afficher l'affiche du film
const displayMoviePoster = async function(posterUrl, titleElement) {
// Convertir l'image en données base64
const base64Image = await getBase64Image(posterUrl);
// Créer un nouveau paragraphe pour l'image
const posterParagraph = document.createElement('p');
// Créer l'image et lui attribuer les données base64
const posterImg = document.createElement('img');
posterImg.src = base64Image;
posterImg.style.maxHeight = '350px';
// Ajouter l'image au paragraphe
posterParagraph.appendChild(posterImg);
// Insérer le paragraphe après le titre
titleElement.parentNode.insertBefore(posterParagraph, titleElement.nextSibling);
};
// Fonction pour convertir une image en données base64
const getBase64Image = async function(url) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "GET",
url: url,
responseType: "blob",
onload: function(response) {
const reader = new FileReader();
reader.onloadend = function() {
resolve(reader.result);
};
reader.onerror = function(error) {
reject(new Error(error));
};
reader.readAsDataURL(response.response);
},
onerror: function(error) {
reject(new Error(error));
}
});
});
};
let titleElements = [];
// Attente jusqu'à ce que des éléments de titre soient disponibles
while (titleElements.length === 0) {
titleElements = $('b > i');
await new Promise(resolve => setTimeout(resolve, 1000)); // Attente de 1 seconde avant de vérifier à nouveau
}
// Pour chaque élément de titre, obtenir le titre, rechercher l'ID IMDb, afficher l'image
for (const titleElement of titleElements) {
const title = $(titleElement).text().trim().replace(/ /g, '+');
const imdbId = await findIMDbId(title);
if (imdbId === 'False') {
continue; // Passer au titre suivant si l'ID IMDb est "False"
}
const details = await getMovieDetails(imdbId);
const posterUrl = details.Poster;
await displayMoviePoster(posterUrl, titleElement);
}
})();