微博聊天循环删除脚本.js
* 2. 按 F12 打开开发者工具
* 3. 切换到 Console(控制台)标签
* 4. 粘贴此脚本并按回车
* 5. 输入 deleteAllConversations() 并回车执行
*/
(function() {
'use strict';
// 配置
const config = {
deleteDelay: 800, // 每次删除后等待时间(毫秒)
maxIterations: 100, // 最大循环次数
showProgress: true // 显示进度
};
限制字数 我服了
抱歉,您的帖子超过 10000 个字符的限制
Google 发表于 2026-2-25 15:09
抱歉,您的帖子超过 10000 个字符的限制
改了,你再试试 抽大烟 发表于 2026-2-25 15:13
改了,你再试试
/**
* 微博聊天一键删除所有会话框 - 循环删除版
*
* 使用方法:
* 1. 打开微博聊天网页版 https://api.weibo.com/chat#/chat 并登录
* 2. 按 F12 打开开发者工具
* 3. 切换到 Console(控制台)标签
* 4. 粘贴此脚本并按回车
* 5. 输入 deleteAllConversations() 并回车执行
*/
(function() {
'use strict';
// 配置
const config = {
deleteDelay: 800, // 每次删除后等待时间(毫秒)
maxIterations: 100, // 最大循环次数
showProgress: true // 显示进度
};
// 多种可能的选择器
const selectors = [
// 聊天列表项
'.chat-item',
'.conversation-item',
'.session-item',
'.list-item',
' > div',
' > div',
' > div',
// 通用选择器
'ul.chat-list > li',
'div > div',
// 查找包含聊天气泡或消息的元素
'',
// 滚动列表中的项目
'.scroll-item',
'.item-wrapper'
];
// 查找所有会话元素
function findConversations() {
let elements = [];
// 尝试每种选择器
for (const selector of selectors) {
const found = document.querySelectorAll(selector);
if (found.length > 0) {
// 过滤掉非会话的元素(如广告、提示等)
elements = Array.from(found).filter(el => {
const text = el.textContent || '';
const className = el.className || '';
// 排除明显不是会话的元素
if (text.includes('广告') || text.includes('推广')) return false;
if (className.includes('header') || className.includes('footer')) return false;
// 保留可能包含用户名/消息的元素
return true;
});
if (elements.length > 0) {
console.log(`使用选择器: ${selector}, 找到 ${elements.length} 个元素`);
return elements;
}
}
}
// 最后尝试:查找所有可能是列表项的元素
const allDivs = document.querySelectorAll('div');
elements = Array.from(allDivs).filter(el => {
const rect = el.getBoundingClientRect();
return rect.width > 100 && rect.height > 30 && rect.height < 200;
});
return elements;
}
// 查找删除按钮
function findDeleteButton(item) {
// 方法1:直接查找带有删除相关文字/属性的按钮
const allButtons = item.querySelectorAll('button, span, div');
for (const btn of allButtons) {
const text = (btn.textContent || '').trim().toLowerCase();
const title = (btn.title || '').toLowerCase();
const className = (btn.className || '').toLowerCase();
if (text.includes('删除') || text.includes('del') ||
title.includes('删除') || className.includes('delete') ||
className.includes('remove')) {
return btn;
}
}
// 方法2:查找图标按钮(删除通常是垃圾桶图标)
const iconButtons = item.querySelectorAll(', svg');
for (const icon of iconButtons) {
const parent = icon.closest('button') || icon.closest('');
if (parent) return parent;
}
return null;
}
// 触发删除
async function triggerDelete(item) {
try {
// 方法1:点击删除按钮
const deleteBtn = findDeleteButton(item);
if (deleteBtn) {
deleteBtn.click();
await wait(300);
// 查找确认对话框
const confirmButtons = document.querySelectorAll('button, div, span');
for (const btn of confirmButtons) {
const text = (btn.textContent || '').trim().toLowerCase();
if (text === '确定' || text === '确认' || text.includes('删除') || text === 'ok' || text === 'yes') {
if (!text.includes('取消')) {
btn.click();
return true;
}
}
}
return true;
}
// 方法2:右键点击唤出菜单
const rect = item.getBoundingClientRect();
item.dispatchEvent(new MouseEvent('contextmenu', {
bubbles: true,
clientX: rect.left + rect.width / 2,
clientY: rect.top + rect.height / 2
}));
await wait(500);
// 查找菜单中的删除选项
const menuItems = document.querySelectorAll(' li, li, li');
for (const menuItem of menuItems) {
const text = (menuItem.textContent || '').toLowerCase();
if (text.includes('删除') || text.includes('del') || text.includes('remove')) {
menuItem.click();
await wait(300);
// 再次确认
const confirmButtons = document.querySelectorAll('button, div');
for (const btn of confirmButtons) {
const btnText = (btn.textContent || '').trim().toLowerCase();
if (btnText === '确定' || btnText === '确认' || btnText === 'ok') {
btn.click();
return true;
}
}
return true;
}
}
// 方法3:直接移除元素(最后手段)
if (item.remove) {
item.remove();
return true;
} else if (item.parentNode) {
item.parentNode.removeChild(item);
return true;
}
return false;
} catch (error) {
console.error('删除出错:', error);
return false;
}
}
// 等待函数
function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// 主函数 - 循环删除所有会话
async function deleteAllConversations() {
console.log('%c 微博聊天 - 循环删除所有会话 ', 'background: #ff6b6b; color: white; font-size: 16px; padding: 10px;');
// 确认
const confirmed = confirm('确定要删除微博聊天的所有会话吗?\n\n脚本将循环删除直到全部删除完成。');
if (!confirmed) {
console.log('已取消');
return;
}
let totalDeleted = 0;
let iteration = 0;
while (iteration < config.maxIterations) {
iteration++;
// 每次都重新获取会话列表
const conversations = findConversations();
if (conversations.length === 0) {
console.log('%c ✓ 所有会话已删除完成! ', 'background: #4ecdc4; color: white; font-size: 14px; padding: 8px;');
console.log(`总计删除: ${totalDeleted} 个会话`);
alert(`删除完成!共删除 ${totalDeleted} 个会话`);
return;
}
if (config.showProgress) {
console.log(`第 ${iteration} 轮:还有 ${conversations.length} 个会话待删除,已删除 ${totalDeleted} 个`);
}
// 删除当前列表中的第一个会话
const item = conversations;
const success = await triggerDelete(item);
if (success) {
totalDeleted++;
}
// 等待DOM更新
await wait(config.deleteDelay);
}
console.log(`已达到最大循环次数 ${config.maxIterations},已删除 ${totalDeleted} 个会话`);
alert(`完成!共删除 ${totalDeleted} 个会话\n如果还有剩余,请刷新页面后重新执行`);
}
// 快速删除模式 - 每次删除多个
async function fastDelete() {
console.log('%c 微博聊天 - 快速删除模式 ', 'background: #45b7d1; color: white; font-size: 16px; padding: 10px;');
const confirmed = confirm('快速删除模式:\n\n将尽可能快地批量删除所有会话');
if (!confirmed) return;
let totalDeleted = 0;
let emptyCount = 0;
while (emptyCount < 5) {
const conversations = findConversations();
if (conversations.length === 0) {
emptyCount++;
await wait(500);
continue;
}
emptyCount = 0;
// 每次尝试删除前3个
const toDelete = conversations.slice(0, 3);
for (const item of toDelete) {
await triggerDelete(item);
}
totalDeleted += toDelete.length;
console.log(`已删除 ${totalDeleted} 个...`);
await wait(config.deleteDelay);
}
alert(`快速删除完成!共删除 ${totalDeleted} 个会话`);
}
// 导出函数
window.deleteAllConversations = deleteAllConversations;
window.fastDelete = fastDelete;
console.log('%c 微博聊天删除脚本已加载 ', 'background: #4ecdc4; color: white; font-size: 14px; padding: 8px;');
console.log('可用函数:');
console.log('deleteAllConversations() - 循环删除所有会话');
console.log('fastDelete() - 快速删除模式');
})(); 还有个终极暴力版本,改了参数好像没什么效果,用一版改下参数反正删完了,此版备份
/**
* 微博聊天一键删除所有会话框 - 终极版
* 针对微博聊天网页版特点优化
*
* 使用方法:
* 1. 打开 https://api.weibo.com/chat#/chat 并登录
* 2. F12 打开开发者工具 → Console
* 3. 粘贴脚本回车
* 4. 输入 deleteAllConversations() 回车执行
*/
(function() {
'use strict';
// 设置参数
const DELAY = 1000;// 每次删除间隔(毫秒)
console.log('%c 微博聊天 - 终极删除脚本 ', 'background: #e74c3c; color: white; font-size: 16px; padding: 10px;');
// 获取会话列表容器
function getChatList() {
// 尝试多种可能的容器选择器
const containers = [
'.chat-list',
'.conversation-list',
'.session-list',
'',
'ul',
''
];
for (const selector of containers) {
const container = document.querySelector(selector);
if (container && container.children.length > 0) {
// 检查是否像会话列表
const children = Array.from(container.children);
const hasChatItems = children.some(child => {
const text = child.textContent || '';
const hasName = /[\u4e00-\u9fa5a-zA-Z0-9]{2,}/.test(text);
return hasName && child.querySelector('img, , ');
});
if (hasChatItems) {
return container;
}
}
}
return null;
}
// 获取所有会话项
function getAllConversations() {
const list = getChatList();
if (!list) {
// 尝试直接获取页面中所有可能是会话的元素
const allElements = document.querySelectorAll('li, div');
return Array.from(allElements).filter(el => {
const rect = el.getBoundingClientRect();
return rect.width > 200 && rect.height > 40 && el.textContent.trim().length > 0;
});
}
return Array.from(list.children).filter(el => {
const text = el.textContent || '';
return text.trim().length > 0 && !text.includes('广告');
});
}
// 尝试点击删除按钮
async function clickDeleteButton(item) {
// 查找所有可能删除按钮
const allElements = item.querySelectorAll('*');
for (const el of allElements) {
const tagName = el.tagName.toLowerCase();
if (tagName !== 'button' && tagName !== 'div' && tagName !== 'span') continue;
const text = (el.textContent || '').trim();
const className = (el.className || '').toLowerCase();
const title = (el.title || '').toLowerCase();
// 判断是否是删除相关按钮
const isDeleteBtn = text === '删除' || text === 'Del' ||
className.includes('delete') || className.includes('del') ||
className.includes('remove') || title.includes('删除');
if (isDeleteBtn) {
// 尝试点击
try {
el.click();
return true;
} catch (e) {
// 尝试其他方式触发点击
const event = new MouseEvent('click', { bubbles: true });
el.dispatchEvent(event);
return true;
}
}
}
// 尝试右键菜单
const rect = item.getBoundingClientRect();
item.dispatchEvent(new MouseEvent('contextmenu', {
bubbles: true,
clientX: rect.left + rect.width / 2,
clientY: rect.top + rect.height / 2
}));
await new Promise(r => setTimeout(r, 500));
// 查找菜单
const menu = document.querySelector('');
if (menu) {
const menuItems = menu.querySelectorAll('li, div, span');
for (const menuItem of menuItems) {
const text = (menuItem.textContent || '').toLowerCase();
if (text.includes('删除') || text.includes('del') || text.includes('remove')) {
menuItem.click();
return true;
}
}
}
return false;
}
// 确认对话框
async function confirmDialog() {
await new Promise(r => setTimeout(r, 300));
// 查找确认按钮
const buttons = document.querySelectorAll('button, , div');
for (const btn of buttons) {
const text = (btn.textContent || '').trim().toLowerCase();
if (text === '确定' || text === '确认' || text === 'ok' || text === 'confirm') {
if (!text.includes('取消')) {
btn.click();
return true;
}
}
}
// 模拟回车确认
document.activeElement?.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter' }));
return true;
}
// 删除单个会话
async function deleteOne(item) {
try {
// 尝试点击删除按钮
const clicked = await clickDeleteButton(item);
if (clicked) {
await confirmDialog();
return true;
}
// 最后手段:直接移除元素
if (item.remove) {
item.remove();
return true;
}
return false;
} catch (e) {
console.error('删除出错:', e);
return false;
}
}
// 主函数
async function deleteAllConversations() {
const confirmed = confirm('确定要删除微博聊天的所有会话吗?\n此操作不可恢复!');
if (!confirmed) return;
let total = 0;
let round = 0;
let emptyRounds = 0;
while (emptyRounds < 3) {
round++;
const items = getAllConversations();
if (items.length === 0) {
emptyRounds++;
await new Promise(r => setTimeout(r, 500));
console.log(`第 ${round} 轮:未找到会话`);
continue;
}
emptyRounds = 0;
console.log(`第 ${round} 轮:还有 ${items.length} 个会话, 已删除 ${total} 个`);
// 删除第一个
const item = items;
const success = await deleteOne(item);
if (success) {
total++;
}
// 等待页面更新
await new Promise(r => setTimeout(r, DELAY));
}
console.log(`%c ✓ 删除完成!共删除 ${total} 个会话 `, 'background: #27ae60; color: white; font-size: 14px; padding: 8px;');
alert(`删除完成!共删除 ${total} 个会话`);
}
// 导出
window.deleteAllConversations = deleteAllConversations;
console.log('脚本已就绪!');
console.log('执行 deleteAllConversations() 开始删除');
})(); deleteDelay: 800, // 每次删除后等待时间(毫秒)
maxIterations: 100, // 最大循环次数
改成100500挂那就行了,好像没被风控
页:
[1]