漫画柜&拷贝漫画搜索按钮(新标签页打开+点击复制标题)

在mox.moe页面添加去漫画柜和拷贝漫画搜索按钮,新标签页打开,点击标题可复制内容

当前为 2025-09-28 提交的版本,查看 最新版本

// ==UserScript==
// @name         漫画柜&拷贝漫画搜索按钮(新标签页打开+点击复制标题)
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  在mox.moe页面添加去漫画柜和拷贝漫画搜索按钮,新标签页打开,点击标题可复制内容
// @author       YourName
// @match        https://mox.moe/c/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        const titleElement = document.querySelector('.text_bglight_big');

        if (titleElement) {
            const mangaTitle = titleElement.textContent.trim();

            // 点击标题复制
            titleElement.style.cursor = 'pointer'; // 给个手型提示
            titleElement.title = '点击复制标题';
            titleElement.addEventListener('click', async function() {
                try {
                    await navigator.clipboard.writeText(mangaTitle);
                } catch (err) {
                    console.error('复制失败: ', err);
                }
            });

            // 通用按钮样式函数
            function createButton(text, bgColor) {
                const btn = document.createElement('button');
                btn.textContent = text;
                btn.style.marginLeft = '10px';
                btn.style.padding = '5px 10px';
                btn.style.backgroundColor = bgColor;
                btn.style.color = 'white';
                btn.style.border = 'none';
                btn.style.borderRadius = '4px';
                btn.style.cursor = 'pointer';
                return btn;
            }

            // 漫画柜搜索按钮
            const searchButton1 = createButton('去漫画柜搜索', '#005CAF');
            searchButton1.addEventListener('click', function() {
                const encodedTitle = encodeURIComponent(mangaTitle);
                window.open(`https://www.manhuagui.com/s/${encodedTitle}.html`, '_blank');
            });

            // 拷贝漫画搜索按钮
            const searchButton2 = createButton('去拷贝漫画搜索', '#AF005C');
            searchButton2.addEventListener('click', function() {
                const encodedTitle = encodeURIComponent(mangaTitle);
                window.open(`https://www.mangacopy.com/search?q=${encodedTitle}`, '_blank');
            });

            // 插入到标题后面
            titleElement.parentNode.insertBefore(searchButton1, titleElement.nextSibling);
            titleElement.parentNode.insertBefore(searchButton2, searchButton1.nextSibling);
        }
    });
})();