// ==UserScript== // @name DS Enhance Max (满血版) [适用最新DeepSeek网页] // @namespace https://chat.deepseek.com/ // @version 8.0.3 // @description 【满血升级】突破原生限制!支持 AI 智能会话搜索、AI 自动化标签整理、多大模型 API 自由切换、原生隔离级批量管理。集成批量删除、导出、自定义提示词以及批量FORK等满血增强功能。 // @author TRYuuu // @license MIT // @match *://chat.deepseek.com/* // @icon https://fe-static.deepseek.com/chat/favicon.svg // @grant none // @run-at document-start // ==/UserScript== /* * MIT License * * Copyright (c) 2026 TRYuuu * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ (function () { 'use strict'; const CONFIG = { listApi: '/api/v0/chat_session/fetch_page', detailApi: '/api/v0/chat_session/fetch_messages', deleteApi: '/api/v0/chat_session/delete', pageSize: 50, deleteInterval: 400, maxConcurrent: 3, }; const LS_PROMPTS = 'dse_prompts'; const CUSTOM_PROMPT_MARKER = '[自定义提示词]'; // ==================== 1. 自定义提示词拦截引擎 (必须在 document-start 执行) ==================== let _capturedToken = null; let lastInjectedSignature = null; // ==================== 状态响应拦截 (实时同步UI) ==================== const origSetItem = localStorage.setItem; localStorage.setItem = function(key, value) { origSetItem.call(this, key, value); if ((key === 'ds_global_tags' || key === 'ds_local_tags') && typeof window.__dsSyncTagUI === 'function') { setTimeout(window.__dsSyncTagUI, 10); } }; const origRemoveItem = localStorage.removeItem; localStorage.removeItem = function(key) { origRemoveItem.call(this, key); if ((key === 'ds_global_tags' || key === 'ds_local_tags') && typeof window.__dsSyncTagUI === 'function') { setTimeout(window.__dsSyncTagUI, 10); } }; // 监听 URL 变化重置指纹(解决切换房间不触发新提示词的问题) const originalPushState = history.pushState; history.pushState = function(...args) { const newUrl = args[2]; if (newUrl) { const oldPath = location.pathname; const newPath = newUrl.toString().startsWith('http') ? new URL(newUrl).pathname : new URL(newUrl, location.origin).pathname; if (oldPath !== '/' && oldPath !== newPath) lastInjectedSignature = null; } return originalPushState.apply(this, args); }; window.addEventListener('popstate', () => { lastInjectedSignature = null; }); function getEnabledPrompts() { try { const arr = JSON.parse(localStorage.getItem(LS_PROMPTS) || '[]'); if (Array.isArray(arr) && arr.length) return arr.filter(p => p.enabled).map(p => p.content).filter(Boolean); } catch(e) {} return []; } function modifyRequest(bodyStr) { const enabled = getEnabledPrompts(); const currentSignature = enabled.join('\n\n'); if (!currentSignature) { lastInjectedSignature = null; return bodyStr; } if (!bodyStr || bodyStr.includes(CUSTOM_PROMPT_MARKER)) return bodyStr; if (lastInjectedSignature === currentSignature) return bodyStr; try { const parsed = JSON.parse(bodyStr); const tagged = `${CUSTOM_PROMPT_MARKER}\n${currentSignature}`; let injected = false; if (parsed.prompt && typeof parsed.prompt === 'string') { parsed.prompt = parsed.prompt + '\n\n' + tagged; injected = true; } if (parsed.messages && parsed.messages.length > 0) { const lastIdx = parsed.messages.length - 1; if (parsed.messages[lastIdx].role === 'USER') { parsed.messages[lastIdx].content = parsed.messages[lastIdx].content + '\n\n' + tagged; injected = true; } } if (injected) { lastInjectedSignature = currentSignature; return JSON.stringify(parsed); } } catch(e) {} return bodyStr; } (function installInterceptor() { const origFetch = window.fetch; window.fetch = async function(input, init = {}) { try { const url = typeof input === 'string' ? input : input?.url || ''; // 捕获 Token if (url.includes('/api/') && init?.headers) { const h = init.headers; const auth = (h instanceof Headers) ? h.get('Authorization') : (h['Authorization'] || h['authorization']); if (auth && auth.startsWith('Bearer ')) _capturedToken = auth.replace(/^Bearer\s+/i, '').trim(); } // 注入提示词 if (url.includes('completion') && init?.body && typeof init.body === 'string') { init.body = modifyRequest(init.body); } } catch(e) {} return origFetch.apply(this, arguments); }; const origOpen = XMLHttpRequest.prototype.open; const origSend = XMLHttpRequest.prototype.send; const origSetHeader = XMLHttpRequest.prototype.setRequestHeader; const _xhrMeta = new WeakMap(); XMLHttpRequest.prototype.open = function(method, url, ...rest) { _xhrMeta.set(this, { url }); return origOpen.apply(this, [method, url, ...rest]); }; XMLHttpRequest.prototype.setRequestHeader = function(name, value) { if (/^authorization$/i.test(name) && typeof value === 'string' && value.startsWith('Bearer ')) { _capturedToken = value.replace(/^Bearer\s+/i, '').trim(); } return origSetHeader.apply(this, arguments); }; XMLHttpRequest.prototype.send = function(body) { const meta = _xhrMeta.get(this); if (meta && meta.url.includes('completion') && typeof body === 'string') { body = modifyRequest(body); } return origSend.apply(this, [body]); }; })(); // ==================== 2. 等待 DOM 准备完毕 ==================== function waitForDOM() { return new Promise(resolve => { if (document.body) resolve(); else new MutationObserver(() => { if (document.body) resolve(); }) .observe(document.documentElement, { childList: true }); }); } waitForDOM().then(() => { // ==================== 以下为 UI 与功能逻辑 ==================== window.dsAlert = function(msg, type = 'success', duration = 3000) { let container = document.getElementById('ds-toast-container'); if (!container) { container = document.createElement('div'); container.id = 'ds-toast-container'; container.className = 'ds-toast-container'; document.body.appendChild(container); } const toast = document.createElement('div'); toast.className = `ds-toast ${type}`; const icon = type === 'success' ? '✅' : type === 'error' ? '❌' : '⚠️'; toast.innerHTML = `${icon}${msg}`; container.appendChild(toast); setTimeout(() => { toast.style.animation = 'ds-toast-out 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards'; setTimeout(() => toast.remove(), 300); }, duration); }; window.dsConfirm = function(msg, title = "操作确认") { return new Promise((resolve) => { const overlay = document.createElement('div'); overlay.className = 'ds-modal-overlay'; overlay.addEventListener('click', (e) => { // Prevent DeepSeek's global document click handler from crashing if (e.target && (e.target.tagName === 'svg' || e.target.tagName === 'path' || e.target.closest('.ds-tab-btn'))) { e.stopPropagation(); } }, true); overlay.innerHTML = `