// ==UserScript== // @name 批量删除QQ空间说说(全自动翻页版) // @namespace http://tampermonkey.net/ // @version 0.4 // @description 批量删除QQ空间说说(自动翻页+强制刷新+500ms间隔) // @match https://user.qzone.qq.com/* // @match https://hbs.qzone.qq.com/* // @original-author 是隔壁老王啊 // @original-license MIT // @original-script https://bbs.tampermonkey.net.cn/thread-7460-1-1.html // @modified-by 浮沉㗊 // @author 浮沉㗊(二改版) // @icon https://www.google.com/s2/favicons?sz=64&domain=user.qzone.qq.com // @grant unsafeWindow // ==/UserScript== (function() { 'use strict'; var g_tk = ''; var g_qq = ''; var isDeleting = false; var retryCount = 0; const MAX_RETRY = 3; // 获取说说列表 function getTidAndContent() { const iframe = document.querySelector('#app_container iframe'); if (!iframe) return []; const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; return Array.from(iframeDoc.querySelectorAll('#msgList > li')).map(li => { const tid = li.getAttribute('data-tid'); const contentElement = li.querySelector('div.box.bgr3 > div.bd > pre'); const content = contentElement ? contentElement.textContent.trim() : ''; return { tid, content }; }); } // 获取GTK function getgtk() { return unsafeWindow.QZFL?.pluginsDefine?.getACSRFToken?.('http://up.qzone.qq.com') || ''; } // 获取QQ号 function getqq() { try { return unsafeWindow.g_iLoginUin || ''; } catch (e) { return ''; } } // 删除单条说说 function deleteEmotion(hostuin, tid, callback) { const url = `https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?&g_tk=${g_tk}`; const data = { hostuin: hostuin, tid: tid, t1_source: 1, code_version: 1, format: 'fs', qzreferrer: `https://user.qzone.qq.com/${hostuin}/infocenter` }; const formBody = Object.keys(data).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}` ).join('&'); fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: formBody }) .then(response => response.text()) .then(htmlText => { const match = htmlText.match(/frameElement\.callback\((.*)\);/); if (match && match[1]) { console.log(`删除成功: ${tid}`); const iframe = document.querySelector('#app_container iframe'); if (iframe) { const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; const li = iframeDoc.querySelector(`li[data-tid="${tid}"]`); if (li) li.remove(); } callback(true); } else { console.error('删除失败:', htmlText); callback(false); } }) .catch(err => { console.error('请求错误:', err); callback(false); }); } // 强制刷新说说列表 function refreshMoodList() { const iframe = document.querySelector('#app_container iframe'); if (!iframe) return false; const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; const myMoodBtn = iframeDoc.querySelector('li.nav_my a'); // "我的说说"按钮 if (myMoodBtn) { myMoodBtn.click(); console.log('已点击"我的说说"刷新列表'); return true; } return false; } // 主删除逻辑 function customAction() { if (isDeleting) { console.log('正在删除中,请等待...'); return; } g_tk = getgtk(); g_qq = getqq(); if (!g_tk || !g_qq) { alert('获取Token或QQ号失败,请刷新页面重试!'); return; } isDeleting = true; retryCount = 0; console.log('开始批量删除...'); const processDeletion = () => { const moods = getTidAndContent(); if (moods.length === 0) { if (retryCount < MAX_RETRY) { retryCount++; console.log(`未找到说说,尝试刷新 (${retryCount}/${MAX_RETRY})...`); if (refreshMoodList()) { setTimeout(processDeletion, 2000); // 2秒后重试 } else { console.log('刷新失败,可能已完成删除'); isDeleting = false; } } else { console.log('已达到最大重试次数,停止删除'); isDeleting = false; } return; } console.log(`当前页找到 ${moods.length} 条说说,开始删除...`); let index = 0; const deleteNext = () => { if (index >= moods.length) { console.log('当前页删除完成,尝试刷新...'); if (refreshMoodList()) { setTimeout(processDeletion, 1500); // 1.5秒后处理新页面 } else { console.log('删除完成!'); isDeleting = false; } return; } deleteEmotion(g_qq, moods[index].tid, (success) => { setTimeout(deleteNext, success ? 500 : 1000); // 成功500ms,失败1秒 index++; }); }; deleteNext(); }; processDeletion(); } // 注入删除按钮 function injectDeleteButton() { const iframe = document.querySelector('#app_container iframe'); if (!iframe) return; const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; const target = iframeDoc.querySelector('li.nav_my'); if (target && !iframeDoc.querySelector('.auto-delete-btn')) { const btn = iframeDoc.createElement('a'); btn.className = 'c-tx2 selected auto-delete-btn'; btn.style.cursor = 'pointer'; btn.innerHTML = '一键删除所有说说'; btn.addEventListener('click', (e) => { e.preventDefault(); if (confirm('一旦执行除非卡死或删后台将不会停止,请三思!——浮沉㗊')) { customAction(); } }); target.parentNode.insertBefore(btn, target.nextSibling); console.log('删除按钮注入成功'); } } // 初始化 function init() { const checkReady = setInterval(() => { const iframe = document.querySelector('#app_container iframe'); if (iframe && iframe.contentDocument) { clearInterval(checkReady); injectDeleteButton(); // 监听iframe变化 new MutationObserver(() => { injectDeleteButton(); }).observe(document.querySelector('#app_container'), { childList: true, subtree: true }); } }, 1000); } // 启动脚本 init(); })();