// ==UserScript== // @name DeepSeek 防撤回脚本 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 防止 DeepSeek 撤回消息,阻止遇到某些内容时候的deepseek自动撤回,修改自b站用户“银空飞羽”的浏览器插件 // @author HiKey // @match https://*.deepseek.com/* // @match https://deepseek.com/* // @grant none // @run-at document-idle // ==/UserScript== (function() { 'use strict'; // 全局缓存对象,记录 div 的内容 let cachedContent = new Map(); console.log("DeepSeek 防撤回已启动"); /** * 移除 HTML 中的所有 SVG 标签 * @param {string} htmlContent * @returns {string} 处理后的 HTML */ function removeSVG(htmlContent) { const tempDiv = document.createElement("div"); tempDiv.innerHTML = htmlContent; // 移除所有 元素 const svgs = tempDiv.querySelectorAll("svg"); svgs.forEach((svg) => svg.remove()); return tempDiv.innerHTML; } function monitorContent() { console.log("[监控] 开始检查内容变化..."); // 打印监控开始日志 const container = document.evaluate( '//*[@id="root"]/div/div/div[2]/div[3]/div/div[2]/div/div/div[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue; if (container) { console.log("[监控] 找到主容器节点。"); // 打印容器找到日志 // 获取所有子 div const divs = container.querySelectorAll(":scope > div"); const lastEvenDiv = Array.from(divs).reverse().find((div, index) => (divs.length - index) % 2 === 0); if (lastEvenDiv) { console.log("[监控] 找到最后一个双数 div:", lastEvenDiv); // 打印最后一个双数 div // 获取当前 div 的完整 HTML 内容,并移除 SVG const newContent = removeSVG(lastEvenDiv.innerHTML); // 如果缓存中不存在该 div,则初始化缓存 if (!cachedContent.has(lastEvenDiv)) { cachedContent.set(lastEvenDiv, newContent); console.log("[缓存] 初始化内容(去除 SVG 后):", newContent); // 打印初始化内容 } else if (newContent !== cachedContent.get(lastEvenDiv)) { console.log("[监控] 内容发生变化!"); // 打印内容变化日志 // 检查是否包含撤回关键词 if (newContent.includes("这个问题我暂时无法回答") || newContent.includes("我还没学会这个问题")) { console.log("[监控] 检测到撤回关键词,恢复缓存内容。"); // 打印检测到撤回的日志 // 替换为缓存内容,并附加撤回标记 lastEvenDiv.innerHTML = cachedContent.get(lastEvenDiv) + `
(原回复已被撤回)
`; } else { // 更新缓存内容 cachedContent.set(lastEvenDiv, newContent); console.log("[缓存] 更新内容(去除 SVG 后):", newContent); // 打印更新后的内容 } } else { console.log("[监控] 内容无变化。"); // 打印内容无变化日志 } } else { console.log("[监控] 未找到符合条件的双数 div。"); // 打印未找到双数 div 的日志 } } else { console.log("[监控] 主容器节点未找到。"); // 打印主容器未找到的日志 } } // 启动监控 setInterval(monitorContent, 1000); // 每秒检查一次 })();