Skip to content

Instantly share code, notes, and snippets.

@hyrious
Created July 14, 2026 03:10
Show Gist options
  • Select an option

  • Save hyrious/48f3680e1a39ebf421af6679016042f4 to your computer and use it in GitHub Desktop.

Select an option

Save hyrious/48f3680e1a39ebf421af6679016042f4 to your computer and use it in GitHub Desktop.
DeepSeek 批量删除对话
// ==UserScript==
// @name DeepSeek 批量删除对话
// @namespace deepseek.hyrious.me
// @version 2026-07-14
// @description 按 ctrl+x 删除当前对话,按 ctrl+shift+x 删除全部对话
// @author hyrious
// @match https://chat.deepseek.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=deepseek.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
function userToken() {
return JSON.parse(localStorage.userToken).value
}
async function api(method, path, body) {
const headers = {
'authorization': 'Bearer ' + userToken(),
'x-client-bundle-id': 'com.deepseek.chat',
'x-client-locale': 'zh_CN',
'x-client-platform': 'web',
'x-client-timezone-offset': '28800',
'x-client-version': '2.2.0'
}
if (method == 'POST') headers['content-type'] = 'application/json';
const init = { method, headers }
if (body) init.body = JSON.stringify(body);
const response = await fetch(path, init)
if (!response.ok) throw new Error(`${await response.text()}` || response.statusText);
const { code, data, msg } = await response.json()
if (code != 0) throw new Error(msg || 'Failed');
return data;
}
function get(path) { return api('GET', path) }
function post(path, body) { return api('POST', path, body) }
async function deleteChatSession(id) {
await post('/api/v0/chat_session/delete', { chat_session_id: id })
}
async function listChatSessions() {
let t = 0, path = '/api/v0/chat_session/fetch_page?lte_cursor.pinned=false', done = false, all = [], seen = new Set()
while (!done) {
const url = path + (t ? `&lte_cursor.updated_at=${t}` : '')
const { biz_data: { chat_sessions, has_more } } = await get(url)
let added = false
for (const a of chat_sessions) {
if (seen.has(a.id)) continue;
seen.add(a.id)
all.push(a)
added = true
t = a.updated_at
}
done = !added || !has_more
}
return all
}
function hasSelection() {
const a = document.activeElement
if (a.tagName === 'INPUT' || a.tagName === 'TEXTAREA') {
return a.selectionStart != a.selectionEnd
} else {
return false
}
}
document.addEventListener('keydown', async function (ev) {
if (ev.ctrlKey && !ev.metaKey && !ev.altKey && ev.code == 'KeyX' && !hasSelection()) {
ev.preventDefault()
if (ev.shiftKey) {
const all = await listChatSessions()
if (all.length) {
if (confirm(`确定删除 ${all.length} 条对话?`)) {
for (const { id } of all) {
await deleteChatSession(id)
await new Promise(r => setTimeout(r, 100))
document.querySelector(`a[href^="/a/chat/s/${id}"]`)?.remove()
}
setTimeout(() => location.replace(location.origin), 50)
}
} else {
alert('当前没有对话可删')
}
} else {
const current = new URL(location.href).pathname.split('/').pop()
if (current) {
await deleteChatSession(current)
setTimeout(() => location.replace(location.origin), 50)
} else {
alert('当前没有对话可删')
}
}
}
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment