博主头像
哎呀博客

Se-Ryong .Blog

自动删除豆包历史会话

F12 控制台 粘贴

// 获取所有菜单按钮
const menuButtons = document.querySelectorAll('.chat-item-menu-button-outline-seq7kq .flex');

const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));

async function deleteItems() {
console.log('👉 开始循环删除流程');

for (let i = 0; i < menuButtons.length; i++) {

console.log(`👉 处理第 ${i + 1} 项`);

// 获取菜单按钮并点击
const menuButton = menuButtons[i];
menuButton.scrollIntoView({ behavior: 'instant', block: 'center' });
simulateClick(menuButton);  // 使用模拟点击
console.log(`✅ 菜单 ${i + 1} 已打开`);

// 2. 等待菜单渲染
await delay(500);

// 3. 查找并点击删除按钮
const removeBtn = await findRemoveButton();
if (removeBtn) {
  removeBtn.scrollIntoView({ behavior: 'instant', block: 'center' });
  simulateClick(removeBtn);  // 使用模拟点击
  console.log(`🗑️ 删除按钮 ${i + 1} 已点击`);
} else {
  console.warn(`❌ 删除按钮 ${i + 1} 未找到`);
  continue;  // 如果没有找到删除按钮,跳过当前项
}

// 4. 等待确认弹窗出现,并确认按钮
await waitForConfirmButton();

// 5. 点击确认弹窗中的“删除”
const confirmDelete = Array.from(document.querySelectorAll('span.semi-button-content[x-semi-prop="children"]'))
  .find(el => el.textContent.trim() === '删除');

if (confirmDelete) {
  confirmDelete.scrollIntoView({ behavior: 'instant', block: 'center' });
  simulateClick(confirmDelete);  // 使用模拟点击
  console.log(`✅ 第 ${i + 1} 项删除已确认`);
} else {
  console.warn(`❌ 确认删除按钮未找到`);
}

// 等待一段时间,避免操作过快
await delay(1000); // 可以调整间隔时间,避免操作过快被页面限制

}

console.log('👉 循环删除流程已完成');
}

// 查找删除按钮
async function findRemoveButton() {
let removeBtn = document.querySelector('li.remove-btn-WbxQPO.select-none.semi-dropdown-item');
return removeBtn;
}

// 等待确认删除按钮出现
async function waitForConfirmButton() {
let confirmDelete = null;
let retries = 0;

while (!confirmDelete && retries < 10) {

confirmDelete = Array.from(document.querySelectorAll('span.semi-button-content[x-semi-prop="children"]'))
  .find(el => el.textContent.trim() === '删除');

if (!confirmDelete) {
  retries++;
  console.log(`⏳ 等待确认按钮出现... 尝试 ${retries}`);
  await delay(500); // 等待500ms重试
}

}

if (confirmDelete) {

console.log('✅ 找到确认删除按钮');

} else {

console.warn('❌ 确认删除按钮未能找到');

}
}

// 模拟点击事件
function simulateClick(element) {
if (element) {

const mouseEvent = new MouseEvent('click', {
  bubbles: true,
  cancelable: true,
  view: window,
  button: 0,  // 左键
  clientX: element.getBoundingClientRect().left + 1,  // 模拟点击的X坐标
  clientY: element.getBoundingClientRect().top + 1   // 模拟点击的Y坐标
});

// 触发 mouseDown 和 mouseUp 事件
const mouseDownEvent = new MouseEvent('mousedown', { bubbles: true, cancelable: true });
const mouseUpEvent = new MouseEvent('mouseup', { bubbles: true, cancelable: true });

element.dispatchEvent(mouseDownEvent);
element.dispatchEvent(mouseUpEvent);
element.dispatchEvent(mouseEvent);  // 最后触发 click 事件

}
}

// 执行循环删除流程
deleteItems();

自动删除豆包历史会话
https://aiya.blog/archives/44.html
本文作者 seryong
发布时间 2025-05-14
许可协议 CC BY-NC-SA 4.0

评论已关闭