您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Add MyAnimeList button to Crunchyroll pages and vice-versa.
当前为
// ==UserScript== // @name CrunchyMAL Cross Search // @namespace CrunchyMAL-CS // @version 2.1 // @description Add MyAnimeList button to Crunchyroll pages and vice-versa. // @author Mattari // @match *://*.crunchyroll.com/* // @match *://*.myanimelist.net/* // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; // General function to create buttons function createButton(text, url, bgColor, textColor) { const button = document.createElement('button'); button.textContent = text; button.style.fontWeight = 'bold'; button.style.marginLeft = '10px'; button.style.padding = '5px 10px'; button.style.borderRadius = '5px'; button.style.border = 'none'; button.style.outline = 'none'; button.style.color = textColor; button.style.backgroundColor = bgColor; button.style.whiteSpace = 'nowrap'; button.onclick = () => { window.open(url, '_blank'); }; return button; } // Function to process Crunchyroll page function processCrunchyrollPage(observer) { try { const h1Element = document.querySelector('div.hero-heading-line h1.title'); if (h1Element && !h1Element.nextElementSibling?.textContent.includes('MyAnimeList')) { // Check if the button is already added const titleText = h1Element.textContent.trim(); const button = createButton('Find\u00A0on\u00A0MyAnimeList', `https://myanimelist.net/search/all?q=${encodeURIComponent(titleText)}`, '#2e4f9e', 'white'); h1Element.insertAdjacentElement('afterend', button); // Stop observing DOM changes immediately after adding the button if (observer) observer.disconnect(); // Unload script and clean up unloadScript(); } } catch (error) { console.error('CrunchyMAL [Error]: ', error); } } // Function to process MyAnimeList page function processMyAnimeListPage() { try { const titleDiv = document.querySelector('div.h1-title'); if (titleDiv && !titleDiv.nextElementSibling?.textContent.includes('CrunchyRoll')) { // Check if the button is already added const titleText = titleDiv.textContent.trim(); const button = createButton('Find\u00A0on\u00A0CrunchyRoll', `https://www.crunchyroll.com/search?from=&q=${encodeURIComponent(titleText)}`, '#ff7b2e', 'white'); titleDiv.insertAdjacentElement('afterend', button); // Unload script and clean up unloadScript(); } } catch (error) { console.error('CrunchyMAL [Error]: ', error); } } // Function to observe DOM changes for Crunchyroll function observeCrunchyrollDOMChanges() { const observer = new MutationObserver(() => processCrunchyrollPage(observer)); observer.observe(document.body, { childList: true, subtree: true }); } // Function to unload the script and clean up function unloadScript() { window.removeEventListener('load', onLoadHandler); if (window.MutationObserver) delete window.MutationObserver; if (window.document) delete window.document; console.log("CrunchyMAL [Info]: Script unloaded and memory cleaned up."); } // Load handler function function onLoadHandler() { try { const hostname = window.location.hostname; const pathname = window.location.pathname; if (hostname.includes('crunchyroll.com')) { observeCrunchyrollDOMChanges(); processCrunchyrollPage(null); } else if (hostname.includes('myanimelist.net') && pathname.startsWith('/anime/')) { processMyAnimeListPage(); } } catch (error) { console.error('CrunchyMAL [Error]: ', error); } } // Ensure the script runs after the page has fully loaded window.addEventListener('load', onLoadHandler); })();