// ==UserScript==
// @name ChatGPT 降级检测
// @namespace http://tampermonkey.net/
// @version 1.5
// @description 仅显示 chat-requirements 请求的 difficulty 和 persona 值,添加动态难度条
// @match *://chatgpt.com/*
// @grant none
// @license AGPLv3
// @downloadURL none
// ==/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 = `
请求信息
Difficulty: N/A
Persona: N/A`;
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;
};
})();