DeepSeek Response Interceptor

该脚本用于拦截DeepSeek屏蔽提示,并输出已缓存文本,重新加载网页失效。

  1. // ==UserScript==
  2. // @name:zh-CN DeepSeek响应拦截器
  3. // @name DeepSeek Response Interceptor
  4. // @namespace https://github.com/Ahikl
  5. // @version 2.0
  6. // @description 该脚本用于拦截DeepSeek屏蔽提示,并输出已缓存文本,重新加载网页失效。
  7. // @author Ahikl
  8. // @match https://chat.deepseek.com/*
  9. // @grant none
  10. // @run-at document-start
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. "use strict";
  16.  
  17. const BLOCKED_TEXT = "content_filter";
  18. let lastValidContent = "";
  19. const chatContainerSelector = ".chat-container";
  20. let chatContainer = null;
  21.  
  22. // 尝试获取聊天容器
  23. function getChatContainer() {
  24. if (!chatContainer) {
  25. chatContainer = document.querySelector(chatContainerSelector);
  26. }
  27. return chatContainer;
  28. }
  29.  
  30. // 更新上一次有效输出
  31. function updateLastValidContent() {
  32. const container = getChatContainer();
  33. if (container) {
  34. lastValidContent = container.innerHTML;
  35. }
  36. }
  37.  
  38. // 回滚到上一次有效输出
  39. function rollbackContent() {
  40. const container = getChatContainer();
  41. if (container) {
  42. console.warn("检测到屏蔽文本,回滚到上一次有效内容。");
  43. container.innerHTML = lastValidContent;
  44. }
  45. }
  46.  
  47. // 重写 fetch 方法,拦截流式响应
  48. const originalFetch = window.fetch;
  49. window.fetch = async function (...args) {
  50. const response = await originalFetch(...args);
  51. if (!response.body) return response;
  52.  
  53. const reader = response.body.getReader();
  54. const decoder = new TextDecoder();
  55. let bufferedText = "";
  56.  
  57. const newStream = new ReadableStream({
  58. start(controller) {
  59. function push() {
  60. reader.read().then(({done, value}) => {
  61. if (done) {
  62. controller.close();
  63. return;
  64. }
  65. const chunk = decoder.decode(value, {stream: true});
  66. bufferedText += chunk;
  67. // 检查是否包含屏蔽文本
  68. if (bufferedText.includes(BLOCKED_TEXT)) {
  69. console.warn("Fetch 检测到屏蔽文本,终止流式响应。");
  70. controller.close();
  71. rollbackContent();
  72. return;
  73. }
  74. controller.enqueue(value);
  75. updateLastValidContent();
  76. push();
  77. }).catch(err => {
  78. console.error("Fetch 处理异常:", err);
  79. controller.error(err);
  80. });
  81. }
  82.  
  83. push();
  84. }
  85. });
  86. return new Response(newStream, {
  87. headers: response.headers,
  88. status: response.status,
  89. statusText: response.statusText,
  90. });
  91. };
  92.  
  93. // 重写 XMLHttpRequest 以拦截请求
  94. const originalXHR = window.XMLHttpRequest;
  95.  
  96. function InterceptedXHR() {
  97. const xhr = new originalXHR();
  98. let bufferedResponse = "";
  99. xhr.addEventListener("readystatechange", function () {
  100. if (xhr.readyState === 3 || xhr.readyState === 4) {
  101. bufferedResponse = xhr.responseText;
  102. if (bufferedResponse.includes(BLOCKED_TEXT)) {
  103. console.warn("XHR 检测到屏蔽文本,终止请求。");
  104. xhr.abort();
  105. rollbackContent();
  106. } else {
  107. updateLastValidContent();
  108. }
  109. }
  110. });
  111. return xhr;
  112. }
  113.  
  114. window.XMLHttpRequest = InterceptedXHR;
  115.  
  116. // 监控 DOM 变化,确保动态插入的内容中不包含屏蔽文本
  117. function setupObserver() {
  118. const container = getChatContainer();
  119. if (!container) return;
  120. const observer = new MutationObserver((mutationsList) => {
  121. for (let mutation of mutationsList) {
  122. if (mutation.type === "childList") {
  123. mutation.addedNodes.forEach((node) => {
  124. let text = "";
  125. if (node.nodeType === Node.TEXT_NODE) {
  126. text = node.textContent;
  127. } else if (node.nodeType === Node.ELEMENT_NODE) {
  128. text = node.innerText || "";
  129. }
  130. if (text && text.includes(BLOCKED_TEXT)) {
  131. console.warn("MutationObserver 检测到屏蔽文本,触发回滚。");
  132. rollbackContent();
  133. }
  134. });
  135. }
  136. }
  137. });
  138. observer.observe(container, {childList: true, subtree: true});
  139. }
  140.  
  141. function initObserver() {
  142. const interval = setInterval(() => {
  143. if (getChatContainer()) {
  144. updateLastValidContent();
  145. setupObserver();
  146. clearInterval(interval);
  147. }
  148. }, 1000);
  149. }
  150.  
  151. window.addEventListener("load", initObserver);
  152.  
  153. console.log("DeepSeek Response Interceptor脚本已注入,用于拦截流式响应并回滚屏蔽内容。");
  154. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址