Adds a "Random Anime" button to Crunchyroll's top navigation bar
当前为
// ==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 });
})();