Greasy Fork

Greasy Fork is available in English.

ChatGPT 降级检测

仅显示 chat-requirements 请求的 difficulty 和 persona 值,添加动态难度条

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ChatGPT 降级检测
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  仅显示 chat-requirements 请求的 difficulty 和 persona 值,添加动态难度条
// @match        *://chatgpt.com/*
// @grant        none
// @license AGPLv3
// ==/UserScript==

(function() {
    'use strict';

    // 创建一个显示框
    const displayBox = document.createElement('div');
    displayBox.style.position = 'fixed';
    displayBox.style.bottom = '20px';
    displayBox.style.right = '20px';
    displayBox.style.width = '220px';
    displayBox.style.padding = '10px';
    displayBox.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
    displayBox.style.color = '#fff';
    displayBox.style.fontSize = '14px';
    displayBox.style.borderRadius = '8px';
    displayBox.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.3)';
    displayBox.style.zIndex = '10000';
    displayBox.innerHTML = `
        <strong>请求信息</strong><br>
        Difficulty: <span id="difficulty">N/A</span> <div id="difficulty-bar" style="width: 100%; height: 10px; border-radius: 5px; background: lightgray; margin-top: 5px;"></div>
        Persona: <span id="persona">N/A</span>`;
    document.body.appendChild(displayBox);

    // 更新难度条颜色
    function updateDifficultyBar(difficulty) {
        const difficultyBar = document.getElementById('difficulty-bar');
        const difficultyNum = parseInt(difficulty, 16);  // 将 16 进制字符串转换为整数
        const maxDifficulty = 0xFFFFFF;  // 假设最高难度为 0xFFFFFF
        const difficultyPercent = 1 - Math.min(difficultyNum / maxDifficulty, 1);  // 计算难度百分比 (1 表示最高难度)

        // 根据难度百分比设置红绿色渐变,0% 红色到 100% 绿色
        const red = Math.floor(255 * (1 - difficultyPercent));
        const green = Math.floor(255 * difficultyPercent);
        difficultyBar.style.backgroundColor = `rgb(${red}, ${green}, 0)`;
        difficultyBar.style.width = `${difficultyPercent * 100}%`;
    }

    // 拦截 fetch 请求
    const originalFetch = window.fetch;
    window.fetch = async function(resource, options) {
        const response = await originalFetch(resource, options);

        // 检查 URL 是否为目标请求
        if (resource.includes('/backend-api/sentinel/chat-requirements') && options.method === 'POST') {
            // 克隆响应以读取其内容
            const clonedResponse = response.clone();
            clonedResponse.json().then(data => {
                const difficulty = data.proofofwork ? data.proofofwork.difficulty : 'N/A';
                const persona = data.persona || 'N/A';
                document.getElementById('difficulty').innerText = difficulty;
                document.getElementById('persona').innerText = persona;

                // 更新难度条
                if (difficulty !== 'N/A') updateDifficultyBar(difficulty);
            }).catch(e => console.error('解析响应时出错:', e));
        }
        return response;
    };
})();