你知道为什么我现在不怎么说话了吗,我现在正在和AI私聊
// ==UserScript==
// @name Toggleable Auto Hide Bot Thinking - BDFZ Forum
// @namespace your_namespace
// @match https://forum.bdfzer.com/t/*
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(function() {
‘use strict’;
let isPluginEnabled = GM_getValue('isPluginEnabled', true);
const originalContentMap = new Map();
let toggleButton;
function isProbablyEnglish(text) {
const englishCharRegex = /[a-zA-Z0-9\s.,!?;:'"(){}\[\]#%^&*+\-=_|<>`~]+/g;
const matches = text.match(englishCharRegex);
if (!matches) return false;
const englishCharLength = matches.join('').length;
return englishCharLength / text.length > 0.5;
}
function hideThinkingProcess() {
if (!isPluginEnabled) return;
const responseElements = document.querySelectorAll('.topic-post .cooked');
responseElements.forEach(element => {
if (originalContentMap.has(element)) return;
originalContentMap.set(element, element.innerHTML);
const textContent = element.textContent;
if (!textContent) return;
const blocks = textContent.split('\n');
let actualResponseContent = "";
let inThinkingProcess = true;
for (const block of blocks) {
const trimmedBlock = block.trim();
if (inThinkingProcess && trimmedBlock && isProbablyEnglish(trimmedBlock)) {
continue;
} else {
inThinkingProcess = false;
actualResponseContent += block + "\n";
}
}
actualResponseContent = actualResponseContent.trim();
if (actualResponseContent) {
element.innerHTML = '';
const responseDiv = document.createElement('div');
responseDiv.textContent = actualResponseContent;
element.appendChild(responseDiv);
}
});
}
function restoreOriginalState() {
originalContentMap.forEach((originalHTML, element) => {
element.innerHTML = originalHTML;
});
}
function createToggleButton() {
toggleButton = document.createElement('button');
updateButtonText();
toggleButton.style.position = 'fixed';
toggleButton.style.top = '10px';
toggleButton.style.right = '10px';
toggleButton.style.zIndex = '9999';
toggleButton.style.padding = '5px 10px';
toggleButton.style.backgroundColor = '#4CAF50';
toggleButton.style.color = 'white';
toggleButton.style.border = 'none';
toggleButton.style.cursor = 'pointer';
toggleButton.onclick = () => {
isPluginEnabled = !isPluginEnabled;
GM_setValue('isPluginEnabled', isPluginEnabled);
updateButtonText();
if (isPluginEnabled) {
hideThinkingProcess();
} else {
restoreOriginalState();
originalContentMap.clear(); // 在禁用时清空 originalContentMap
}
};
}
function updateButtonText() {
if (toggleButton) {
toggleButton.textContent = isPluginEnabled ? '禁用自动隐藏思考' : '启用自动隐藏思考';
}
}
// 确保按钮在 DOM 加载完成后添加,并且添加到 body 的末尾
window.addEventListener('load', () => {
createToggleButton();
document.body.appendChild(toggleButton); // 添加到 body 末尾
if (isPluginEnabled) {
hideThinkingProcess();
}
});
const intervalId = setInterval(() => {
if (isPluginEnabled) {
hideThinkingProcess();
}
}, 1000);
})();
找AI写了一个插件,用于去除英文思考过程,放在篡改猴里就可以使用。
目前这个插件存在的问题有:
检测不准确,isProbablyEnglish()函数是一个非常粗糙的方法,有待改进
会破坏文字特效的结构,比如加粗,斜体等,另外投票和折叠功能等依赖英文代码的内容会被误删。
按钮只能生效一次,之后程序不会再运行
会把报错信息加入页面,无效信息更多了……