// ==UserScript== // @name 批量删除QQ空间说说 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 批量删除QQ空间说说 // @match https://user.qzone.qq.com/* // @match https://h5.qzone.qq.com/* // @author FedoraLinux // @icon https://www.google.com/s2/favicons?sz=64&domain=user.qzone.qq.com // @grant GM_addStyle // @grant unsafeWindow // @grant GM_setClipboard // ==/UserScript== (function() { 'use strict'; var g_tk = ''; var g_qq = ''; 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 }; }); } function getgtk(){ return QZFL.pluginsDefine.getACSRFToken('http://up.qzone.qq.com'); } function getqq(){ try { const topDocument = window.top.document; const scripts = topDocument.querySelectorAll('script'); let g_iLoginUin = null; scripts.forEach(script => { const scriptContent = script.innerHTML; const match = scriptContent.match(/g_iLoginUin=(\d+);/); if (match && match[1]) { g_iLoginUin = match[1]; } }); if (g_iLoginUin) { return g_iLoginUin; //console.log('g_iLoginUin:', g_iLoginUin); } else { return ''; //console.log('未找到 g_iLoginUin'); } } catch (error) { return ''; //console.error('无法访问顶层窗口的内容:', error); } } function deleteEmotion(hostuin, tid) { 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 callbackMatch = htmlText.match(/frameElement\.callback\((.*)\);/);// 使用正则表达式提取 JSON 内容 if (callbackMatch && callbackMatch[1]) { const jsonResponse = JSON.parse(callbackMatch[1]); // console.log('Success:', jsonResponse); const iframe = document.querySelector('#app_container iframe'); if (iframe){ const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; const olElement = iframeDoc.querySelectorAll('#msgList > li'); if (olElement) { for (let li of olElement) { if (li.getAttribute('data-tid') === tid) { li.remove(); break; } } } } } else { console.error('Error: Unable to extract JSON from response'); } }) .catch(error => console.error('Error:', error)); } function customAction() { const resultList = getTidAndContent(); resultList.forEach(item => { // console.log(`TID: ${item.tid}, Content: ${item.content}`); if (item.content === '1') { deleteEmotion(g_qq, item.tid); } }); } function insertNewAElement() { const iframe = document.querySelector('#app_container iframe'); if (!iframe) return; const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; const targetDiv = iframeDoc.querySelector('body > div.mod_wrap.bg.mod-wrap > div.mod_wrap_inner > div.bor.mod-tab.author_display > div > ul > li.nav_my'); if (targetDiv && !targetDiv.querySelector('.new-custom-link')) { const newAElement = iframeDoc.createElement('a'); newAElement.href = 'javascript:void(0);'; newAElement.className = 'c-tx2 selected new-custom-link'; // Add the unique class here newAElement.style.cursor = 'pointer'; const spanElement = iframeDoc.createElement('span'); spanElement.className = 'item-wrap bor-tx'; spanElement.textContent = '**批量删除说说**'; newAElement.appendChild(spanElement); targetDiv.appendChild(newAElement); newAElement.addEventListener('click', function(e) { e.preventDefault(); customAction(); }); console.log('脚本注入成功!'); } else { console.log('删除按钮已经存在!'); } } function waitForIframeAndInsert() { const checkInterval = setInterval(() => { const iframe = document.querySelector('#app_container iframe'); if (iframe && iframe.contentDocument.readyState === 'complete') { clearInterval(checkInterval); setTimeout(insertNewAElement, 500); // 给页面一些额外的时间来完全渲染 } }, 5000); } function setupUnloadListener() { g_tk = getgtk(); g_qq = getqq(); console.log('g_tk: ', g_tk, 'g_qq: ', g_qq); const appContainer = document.querySelector('#app_container'); if (!appContainer) return; const config = { childList: true, subtree: true }; const observer = new MutationObserver((mutations) => { for (let mutation of mutations) { if (mutation.type === 'childList') { const addedNodes = Array.from(mutation.addedNodes); const iframe = addedNodes.find(node => node.tagName === 'IFRAME'); if (iframe) { iframe.addEventListener('load', () => { console.log('iframe 已加载,正在尝试插入元素'); setTimeout(insertNewAElement, 500); }); iframe.contentWindow.addEventListener('unload', () => { console.log('iframe 已卸载,正在等待新内容'); waitForIframeAndInsert(); }); } } } }); observer.observe(appContainer, config); } // 初始插入 waitForIframeAndInsert(); // 设置unload监听器 setupUnloadListener(); })();