MyAnimeList(MAL) - Thumbnail Switch

When on an anime/manga/character page, you will automatically cycle through other available pictures.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

You will need to install an extension such as Tampermonkey to install this script.

Tendrás que instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Tendrás que instalar una extensión como Tampermonkey antes de poder instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         MyAnimeList(MAL) - Thumbnail Switch
// @namespace    https://greasyfork.org/users/16080
// @version      1.0.4
// @description  When on an anime/manga/character page, you will automatically cycle through other available pictures.
// @author       Cpt_mathix
// @match        https://myanimelist.net/anime/*
// @match        https://myanimelist.net/manga/*
// @match        https://myanimelist.net/character/*
// @match        https://myanimelist.net/anime.php?*
// @match        https://myanimelist.net/manga.php?*
// @match        https://myanimelist.net/character.php?*
// @exclude      /^https?:\/\/myanimelist\.net\/(anime|manga|character)\/[^0-9]+/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // find image in html + get anime/manga/character id
    let anchor = document.getElementById("addtolist") || document.getElementById("profileRows");
    let canvas = anchor.parentElement.firstElementChild.firstElementChild;
    let image = canvas.firstElementChild;
    let id = canvas.href.match(/\/\d+\//g)[0].replace(/\//g, "");

    // get type (anime/manga/character)
    let type;
    if (/https:\/\/myanimelist.net\/anime\/.*/.test(canvas.href)) {
        type = "anime";
    } else if (/https:\/\/myanimelist.net\/manga\/.*/.test(canvas.href)) {
        type = "manga";
    } else if (/https:\/\/myanimelist.net\/character\/.*/.test(canvas.href)) {
        type = "characters";
    }

    // remove default click behavior
    canvas.href = "javascript:;";

    // change some styling for image cycling
    canvas.style.position = "relative";
    canvas.style.height = "350px";
    canvas.style.display = "block";
    image.style.transition = "opacity 1s ease-in-out";

    let curr = 0;
    let images = null;

    // fetch all images for given type and id
    fetch('https://api.jikan.moe/v4/' + type + '/' + id + '/pictures').then(function(response) {
        return response.json();
    }).then(function(json) {
        images = json.data;

        // shuffle images in random order
        for (let i = images.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            [images[i], images[j]] = [images[j], images[i]];
        }

        // make sure that the first random image is not the default image
        if (images[0].small === image.src) {
            images.push(images.shift());
        }

        cycle();

        // cycle through images each 3000ms (3s)
        setInterval(cycle, 3000);
    });

    // cycle when clicking
    canvas.addEventListener("click", function(event) {
        event.preventDefault();

        if (images) {
            cycle();
        }
    });

    function cycle() {
        if (++curr === images.length) {
            curr = 0;
        }

        let new_image = document.createElement("img");
        new_image.classList.add("ac");
        new_image.setAttribute("style", "width: 100%; max-height: 350px; position: absolute; opacity: 1; transition: opacity 1s ease-in-out;");
        new_image.onload = function() {
            canvas.insertBefore(new_image, canvas.firstChild);
            canvas.children[0].style.opacity = 100;
            canvas.children[1].style.opacity = 0;

            setTimeout(function() {
                canvas.children[0].style.position = "";
                canvas.children[1].remove()
            }, 1000);
        }

        let next_image_src = images[curr].jpg.image_url;
        new_image.src = next_image_src;
    }
})();