Crunchyroll Random Anime Button

Adds a "Random Anime" button to Crunchyroll's top navigation bar

Tính đến 18-12-2024. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Crunchyroll Random Anime Button
// @namespace    http://tampermonkey.net/
// @version      1.1.0
// @description  Adds a "Random Anime" button to Crunchyroll's top navigation bar
// @icon         https://github.com/noahbds/crunchyroll-random-anime/blob/main/icons/randomimg.png?raw=true
// @author       Noahbds
// @match        https://www.crunchyroll.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const iconUrl = 'https://github.com/noahbds/crunchyroll-random-anime/blob/main/icons/randomimg.png?raw=true';

    function createRandomAnimeButton() {
        const headerActions = document.querySelector('.header-actions ul.erc-user-actions');
        if (!headerActions) return;

        const randomButtonLi = document.createElement('li');
        randomButtonLi.className = 'user-actions-item';

        const randomButton = document.createElement('a');
        randomButton.href = 'https://www.crunchyroll.com/fr/random/anime?random_ref=topbar';
        randomButton.className = 'erc-header-tile state-icon-only erc-random-header-button';
        randomButton.tabIndex = 0;
        randomButton.dataset.t = 'header-tile';

        const buttonDiv = document.createElement('div');
        buttonDiv.className = 'erc-header-svg';

        const buttonIcon = document.createElement('img');
        buttonIcon.src = iconUrl;
        buttonIcon.alt = 'Random Anime Icon';
        buttonIcon.style.cssText = 'width: 24px; height: 24px; display: inline-block; vertical-align: middle; margin-right: 8px;';

        const buttonText = document.createElement('span');
        buttonText.className = 'text--gq6o- text--is-l--iccTo';
        buttonText.textContent = 'Random Anime';

        buttonDiv.appendChild(buttonIcon);
        randomButton.appendChild(buttonDiv);
        randomButton.appendChild(buttonText);
        randomButtonLi.appendChild(randomButton);

        const searchButton = document.querySelector('.erc-search-header-button');
        if (searchButton) {
            headerActions.insertBefore(randomButtonLi, searchButton.parentNode);
        }
    }

    const observer = new MutationObserver(() => {
        if (document.querySelector('.header-actions ul.erc-user-actions')) {
            createRandomAnimeButton();
            observer.disconnect();
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();