CRABPT Combined Tools(发种和有声书)

Combined tools for CRABPT including Ximalaya Information Extractor and Auto Selector

当前为 2025-06-11 提交的版本,查看 最新版本

// ==UserScript==
// @name         CRABPT Combined Tools(发种和有声书)
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Combined tools for CRABPT including Ximalaya Information Extractor and Auto Selector
// @author       Crabpt
// @license      Crabpt
// @match        https://www.ximalaya.com/*
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=crabpt.vip
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // 声明信息
    const DISCLAIMER = `
[size=4][color=#FF0000][b]郑重声明:[/b][/color][/size]
[quote][color=#666666]
本站提供的所有影视作品均是在网上搜集,任何涉及商业盈利目的均不得使用,否则产生的一切后果将由您自己承担!
本站不对本站的任何内容负任何法律责任!该下载内容仅做宽带测试使用,请在下载后24小时内删除。请购买正版!
本站列出的文件没有保存在本站的服务器上,本站仅负责连接,本站对被传播文件的内容一无所知。
本站的链接均由用户自发提供,管理员无法对用户的提交内容或其他行为负责。
[/color][/quote]`;

    // Ximalaya Information Extractor 部分
    function createCopyButton() {
        const button = document.createElement('button');
        button.textContent = '复制信息';
        button.style.position = 'fixed';
        button.style.top = '20px';
        button.style.right = '20px';
        button.style.zIndex = '9999';
        button.style.padding = '10px';
        button.style.backgroundColor = '#fc5832';
        button.style.color = 'white';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';

        button.addEventListener('click', extractAndCopyInfo);
        document.body.appendChild(button);
    }

    function processText(text) {
        if (!text) return '';

        const sections = text.split('\n\n');
        const processedSections = [];
        let skipSection = false;

        for (let i = 0; i < sections.length; i++) {
            const section = sections[i].trim();

            if (!section) continue;

            if (section.includes('购买须知') ||
                section.includes('本作品为付费有声书') ||
                section.includes('版权归原作者所有') ||
                section.includes('如在充值/购买环节遇到问题') ||
                section.includes('在购买过程中')) {
                skipSection = true;
                continue;
            }

            if (section === 'staff' || section === 'cast' || section.includes('内容简介')) {
                skipSection = false;
            }

            if (skipSection) continue;

            if (section.includes('【冒泡有奖】')) {
                processedSections.push(`[quote][color=#FF6B6B]${section}[/color][/quote]`);
            } else if (section.startsWith('版权方:') || section.startsWith('作  者:') ||
                      section.startsWith('策  划:') || section.startsWith('画  本:')) {
                processedSections.push(`[*]${section}`);
            } else if (section.startsWith('男:') || section.startsWith('女:')) {
                const lines = section.split('\n').filter(line => line.trim());
                processedSections.push(lines.join('\n'));
            } else {
                processedSections.push(section);
            }
        }

        return processedSections.join('\n');
    }

    function extractAndCopyInfo() {
        const currentUrl = window.location.href;
        const mainImage = document.querySelector('.img.z_i');
        const mainImageUrl = mainImage ? mainImage.src : '';
        const articleImage = document.querySelector('article.intro img');
        const displayImageUrl = articleImage ? articleImage.src : '';
        const title = document.querySelector('h1.title.z_i');
        const titleText = title ? title.textContent.trim() : '';

        const article = document.querySelector('article.intro');
        let introText = '';
        if (article) {
            const paragraphs = article.querySelectorAll('p');
            introText = Array.from(paragraphs)
                .map(p => p.textContent.trim())
                .filter(text => text)
                .join('\n\n');
        }

        const formattedText = `[center][size=6][color=#FC5832][b]${titleText}[/b][/color][/size][/center]

[center][size=5][color=#2C3E50][b]━━━━━ 封面展示 ━━━━━[/b][/color][/size][/center]
[center][img]${mainImageUrl}[/img][/center]

[center][size=5][color=#2C3E50][b]━━━━━ 详情介绍 ━━━━━[/b][/color][/size][/center]
[center][img]${displayImageUrl}[/img][/center]

[quote][size=4][color=#2C3E50][b]内容简介[/b][/color][/size]
${processText(introText)}[/quote]

[size=4][color=#2C3E50][b]资源信息[/b][/color][/size]
[quote][color=#666666]原网址:[url=${currentUrl}]${currentUrl}[/url][/color][/quote]

${DISCLAIMER}

[center][size=3][color=#999999]━━━━━ CRABPT ━━━━━[/color][/size][/center]`;

        navigator.clipboard.writeText(formattedText).then(() => {
            alert('信息已复制到剪贴板!');
        }).catch(err => {
            console.error('复制失败:', err);
            alert('复制失败,请手动复制');
        });
    }

    // 自动选择器部分
    const TARGETS = [
        {
            selector: 'select[name="team_sel[6]"]',
            targetValue: "",
            targetText: "红叶",
            eventName: "change"
        },
        {
            selector: 'select[name="type"][id="specialcat"]',
            targetValue: "411",
            targetText: "有声书 / Audiobook",
            eventName: "change",
            customHandler: "disableother('specialcat','browsecat')"
        }
    ];

    function autoSelect(target) {
        const el = document.querySelector(target.selector);
        if (!el) return false;

        const option = Array.from(el.options).find(opt =>
            (target.targetValue && opt.value === target.targetValue) ||
            opt.text.includes(target.targetText)
        );

        if (option) {
            el.value = option.value;
            const event = new Event(target.eventName, {
                bubbles: true,
                cancelable: true
            });
            el.dispatchEvent(event);

            if (target.customHandler) {
                new Function(target.customHandler)();
            }
            return true;
        }
        return false;
    }

    function executeSelections() {
        TARGETS.forEach(target => {
            const success = autoSelect(target);
            console.log(`${target.targetText}: ${success ? '成功' : '失败'}`);
        });
    }

    // 初始化
    function init() {
        // 如果在喜马拉雅页面,创建复制按钮
        if (window.location.hostname.includes('ximalaya.com')) {
            createCopyButton();
        }

        // 设置自动选择器的观察器
        const observer = new MutationObserver(mutations => {
            if (TARGETS.some(t => document.querySelector(t.selector))) {
                executeSelections();
            }
        });

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

        if (document.readyState === 'complete') {
            setTimeout(executeSelections, 800);
        }
    }

    window.addEventListener('DOMContentLoaded', init);
    window.addEventListener('load', init);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址