Greasy Fork 支持简体中文。

自欺欺人彩虹ID

PT站点用户名自动添加动态彩虹样式.如果想要适配PT站点请联系我:[email protected]

// ==UserScript==
// @name         自欺欺人彩虹ID
// @namespace    https://example.com/
// @version      1.1
// @description  PT站点用户名自动添加动态彩虹样式.如果想要适配PT站点请联系我:[email protected]
// @license MIT
// @copyright (c) 2025-01-01
// @author       wiiii
// @match        *://pt.m-team.cc/*userdetails.php*
// @match        *://kp.m-team.cc/*userdetails.php*
// @match        *://xp.m-team.io/*userdetails.php*
// @match        *://pt.btschool.club/userdetails.php*
// @match        *://www.haidan.video/userdetails.php*
// @match        *://www.hddolby.com/userdetails.php*
// @match        *://www.hdarea.co/userdetails.php*
// @match        *://hdatmos.club/userdetails.php*
// @match        *://hdhome.org/userdetails.php*
// @match        *://hdsky.me/userdetails.php*
// @match        *://hdtime.org/userdetails.php*
// @match        *://hhanclub.top/userdetails.php*
// @match        *://rousi.zip/userdetails.php*
// @match        *://lemonhd.org/details*
// @match        *://pt.soulvoice.club/userdetails.php*
// @match        *://avgv.cc/userdetails.php*
// @match        *://ptsbao.club/userdetails.php*
// @match        *://www.beitai.pt/userdetails.php*
// @match        *://et8.org/userdetails.php*
// @match        *://pt.eastgame.org/userdetails.php*
// @match        *://pthome.net/userdetails.php*
// @match        *://pterclub.com/userdetails.php*
// @match        *://ourbits.club/userdetails.php*
// @match        *://hdzone.me/userdetails.php*
// @match        *://pt.msg.vg/userdetails.php*
// @match        *://hdfans.org/userdetails.php*
// @match        *://carpt.net/userdetails.php*
// @match        *://www.tjupt.org/userdetails.php*
// @match        *://yingk.com/userdetails.php*
// @match        *://www.dragonhd.xyz/userdetails.php*
// @match        *://chdbits.co/userdetails.php*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // 动态插入 CSS 样式到页面中
    let style = document.createElement('style');

    // 允许的颜色数量选项
    const allowedColors = [10, 20, 50, 100];

    // 获取当前站点的域名
    const currentSite = window.location.hostname;

    // 检查 localStorage 中是否已保存该站点的彩虹设置
    const siteSettings = JSON.parse(localStorage.getItem('rainbowSettings') || '{}');
    const now = Date.now();
    const expirationTime = 180 * 24 * 60 * 60 * 1000; // 180 天(以毫秒为单位)

    // 检查站点状态或缓存是否过期
    function isSettingExpired(timestamp) {
        return now - timestamp >= expirationTime; // 如果超过 180 天则返回 true
    }

    // 控制台日志输出函数
    function logMessage(message, color) {
        console.log(`%c${message}`, `color: ${color}; font-weight: bold;`);
    }

    // 获取渐变颜色
    function generateGradientColors(steps) {
        const colors = [];
        const hueStep = 360 / steps; // 每一步的色相间隔
        for (let i = 0; i < steps; i++) {
            const hue = i * hueStep; // 当前颜色的色相
            colors.push(`hsl(${hue}, 100%, 50%)`); // 使用 HSL 模式生成颜色
        }
        return colors.join(', '); // 返回逗号分隔的颜色字符串
    }

    // 提示用户选择颜色数量
    function getGradientStepCount() {
        let gradientStepCount = parseInt(prompt(`请选择彩虹渐变颜色数量(仅允许输入:10、20、50、100):`, allowedColors.includes(siteSettings[currentSite]?.colors) ? siteSettings[currentSite].colors : 20), 10);
        while (!allowedColors.includes(gradientStepCount)) {
            alert(`输入无效!请仅输入以下选项之一:${allowedColors.join('、')}`);
            gradientStepCount = parseInt(prompt(`请选择彩虹渐变颜色数量(仅允许输入:10、20、50、100):`, '20'), 10);
        }
        return gradientStepCount;
    }

    // 功能:为匹配的 ID 应用彩虹样式
    function applyRainbowEffect(userId, gradientStepCount) {
        const links = document.querySelectorAll('a');
        links.forEach(function (link) {
            const href = link.getAttribute('href'); // 获取 href 属性值
            if (href && href.includes(`userdetails.php?id=${userId}`)) {
                const boldElement = link.querySelector('b'); // 找到嵌套的 <b> 标签
                if (boldElement) {
                    boldElement.classList.add('beautifulrainbow'); // 为 <b> 标签添加彩虹样式
                    logMessage(`为链接 ${href} 添加了彩虹样式`, 'green');
                }
            }
        });

        // 动态生成 CSS 样式
        style.textContent = `
            /* 彩虹样式 */
            .beautifulrainbow {
                display: inline-block !important;
                margin: 0 !important;
                padding: 0 !important;
                font-size: inherit !important;
                line-height: inherit !important;
                text-align: center !important;
                text-decoration: none !important;
                background: linear-gradient(
                    to right,
                    ${generateGradientColors(gradientStepCount)} /* 动态生成的渐变颜色 */
                );
                background-size: ${gradientStepCount * 10}% 100%; /* 根据颜色数量调整背景尺寸 */
                -webkit-background-clip: text !important;
                background-clip: text !important;
                color: transparent !important;
                animation: beautifulrainbow_animation 8s linear infinite alternate; /* 动画时间为 8 秒 */
            }

            /* 动态彩虹动画 */
            @keyframes beautifulrainbow_animation {
                0% { background-position: 0% 50%; }
                100% { background-position: 100% 50%; }
            }
        `;
        document.head.appendChild(style);
    }

    // 检查站点是否启用
    if (siteSettings[currentSite] && !isSettingExpired(siteSettings[currentSite].timestamp)) {
        // 如果 180 天内已有设置(启用或禁用)
        if (siteSettings[currentSite].status === 'DISABLED') {
            logMessage(`彩虹效果已禁用(180 天有效期内),站点:${currentSite}`, 'red');
            return; // 直接退出脚本
        } else if (siteSettings[currentSite].status === 'PENDING') {
            // 如果启用了但未输入 ID,提示用户输入 ID
            const userId = prompt('您已启用彩虹效果,但尚未输入您的 ID。\n\n请输入您的用户 ID(例如:userdetails.php?id=12345):');
            if (userId) {
                const gradientStepCount = siteSettings[currentSite].colors || getGradientStepCount(); // 获取缓存的颜色数量
                siteSettings[currentSite] = {
                    status: userId,
                    colors: gradientStepCount,
                    timestamp: now
                };
                localStorage.setItem('rainbowSettings', JSON.stringify(siteSettings));
                alert('彩虹效果已应用!页面将动态处理您的 ID。');
                logMessage(`彩虹效果已启用,输入的 ID 为 ${userId},站点:${currentSite},颜色数量:${gradientStepCount}`, 'green');
                applyRainbowEffect(userId, gradientStepCount); // 动态应用彩虹效果
            } else {
                alert('您未输入 ID,彩虹效果暂时未启用。找到您的 ID 后可以再次输入。');
                logMessage(`用户未输入 ID,彩虹效果暂时未启用,站点:${currentSite}`, 'red');
            }
            return;
        } else if (siteSettings[currentSite].status) {
            const gradientStepCount = siteSettings[currentSite].colors || 20; // 使用缓存的颜色数量
            applyRainbowEffect(siteSettings[currentSite].status, gradientStepCount); // 应用彩虹效果
            logMessage(`彩虹效果正在应用(180 天有效期内),站点:${currentSite},用户 ID:${siteSettings[currentSite].status},颜色数量:${gradientStepCount}`, 'green');
            return;
        }
    }

    // 如果没有记录或状态已过期,重新提示用户
    const enableRainbow = confirm(`是否为当前站点 (${currentSite}) 启用彩虹效果?`);
    if (enableRainbow) {
        // 记录启用状态但未输入 ID
        const gradientStepCount = getGradientStepCount(); // 获取用户输入的颜色数量
        siteSettings[currentSite] = {
            status: 'PENDING',
            colors: gradientStepCount,
            timestamp: now
        };
        localStorage.setItem('rainbowSettings', JSON.stringify(siteSettings));
        alert(`彩虹效果已启用!渐变颜色数量设置为 ${gradientStepCount},请找到您的 ID 后输入。`);
        logMessage(`彩虹效果已启用,但未输入 ID,站点:${currentSite},渐变颜色数量:${gradientStepCount}`, 'green');
    } else {
        // 如果用户选择不启用插件
        siteSettings[currentSite] = {
            status: 'DISABLED',
            colors: null,
            timestamp: now
        };
        localStorage.setItem('rainbowSettings', JSON.stringify(siteSettings));
        alert('您已选择不启用彩虹效果,180 天内不再提示。');
        logMessage(`彩虹效果已禁用,站点:${currentSite}`, 'red');
    }
})();