Crunchyroll Random Anime Button

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

目前為 2025-01-21 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Crunchyroll Random Anime Button
// @namespace    http://tampermonkey.net/
// @version      1.2.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('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-old');
        if (searchButton) {
            headerActions.insertBefore(randomButtonLi, searchButton.parentNode);
        } else {
            headerActions.appendChild(randomButtonLi);
        }
    }

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

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