我当前的时间:2024.8.18
脚本可以直接使用,随着时间推移,微博页面元素可能会有变动。
思路:javascript 模拟手动点击,下滑,并且删除博文
首先登录微博,进入自己的博文界面如下:
进入当前页面F12 ,控制台直接执行即可(当前脚本只能从上往下删,且没有跳过,如果需要,可自行扩展)
代码(选其一即可):
//一、优化后最强版本(可长时间执行,但也不保证不会停止)--------------------------------------------------------------------------------------------------------------------------------
{function deleteMessage() {try {var scroHeight = 700; //向下滑动的高度 px// 更多按钮let iDom = document.getElementsByClassName('woo-font woo-font--angleDown morepop_action_bk3Fq')[0];if (iDom) {//先找到当前博文var currentcontext = iDom.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;//一、蓝色警方通告var tonggao = currentcontext.getElementsByClassName('woo-box-flex woo-box-alignCenter woo-box-justifyCenter woo-tip-main woo-tip-flat woo-tip-warn tips_tip_3WqKM tips_cursor_2uylm')[0];if (tonggao)//找到当前通告的话,删除当前整个博文,并return,并向下滑动{//根据通告框找到当前最高级别(用于删除)var tonggaoParent = tonggao.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;//1、先删除自己tonggaoParent.parentNode.removeChild(tonggaoParent);//2、再向下滑动window.scrollBy({top: scroHeight,behavior: 'smooth' // 可选,使滚动平滑进行});return;}//二、黄色举报通告var jubao = currentcontext.getElementsByClassName('woo-box-flex woo-box-alignCenter woo-box-justifyCenter woo-tip-main woo-tip-flat woo-tip-error tips_tip_3WqKM tips_cursor_2uylm')[0];if (jubao)//找到当前通告的话,删除当前整个博文,并return,并向下滑动{//根据通告框找到当前最高级别(用于删除)var tonggaoParent = jubao.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;//1、先删除自己tonggaoParent.parentNode.removeChild(tonggaoParent);//在向下滑动window.scrollBy({top: scroHeight,behavior: 'smooth' // 可选,使滚动平滑进行});return;}当前博文做屏幕居中操作获取元素相对于视口的位置//var elementRect = iDom.getBoundingClientRect();计算滚动位置//var offsetTop = elementRect.top + window.scrollY - (window.innerHeight / 2) + (elementRect.height / 2);滚动到指定位置//window.scrollTo({// top: offsetTop,// behavior: 'smooth'//});iDom.scrollIntoView({behavior: 'smooth',block: 'center',inline: 'center'});iDom.click();setTimeout(() => {let deleteOptions = document.getElementsByClassName('woo-box-flex woo-box-alignCenter woo-pop-item-main');// 循环更多列表内的按钮for (let option of deleteOptions) {// 只对删除按钮点击if (option.textContent.trim() == '删除' || option.textContent.trim() == '取消快转') {option.click();setTimeout(() => {// 等待删除对话框出现后再点击确定按钮var dialogCtrl = document.querySelector('.woo-dialog-ctrl');if (dialogCtrl) {// 删除弹窗的确定按钮var secondButton = dialogCtrl.querySelectorAll('button')[1].click();console.log("删除成功了");}}, 200);break;}}}, 100);}} catch (error) {// 异常捕获console.error("郭哥报错了!:", error);}}var timerIdMins = [];var timers = setInterval(function () {//怕有空白处可能导致js不执行,所以刷新一下微博列表var buttons = document.querySelectorAll('.Profile_btn_4Wj2Q');if (buttons.length > 1) {buttons[1].click();// 点击第二个按钮“微博”} else {return;}//阻塞函数function blockForThreeSeconds() {return new Promise(resolve => {setTimeout(resolve, 2000);});}//阻塞函数function blockForThreeSeconds22() {return new Promise(resolve => {setTimeout(resolve, 500);});}//blockForThreeSeconds().then(() => {// setInterval(deleteMessage, 200); //白天快速版本//});blockForThreeSeconds().then(() => {// 获取微博数var element = document.querySelector('.wbpro-screen-v2 > div:first-child');var number = 0;if (element) {var text = element.textContent.trim();// 提取数字部分number = text.match(/\d+/);blockForThreeSeconds22().then(() => {timerIdMins.push(setInterval(function () {//达到数量停止定时器if (number < 100000 && number != null && number != 0) {timerIdMins.forEach(function (timerId) {clearInterval(timerId);});//clearInterval(timers); //先不删大定时器console.log("所有定时器已停止,已经删够啦!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!剩余:" + number);return;}else {deleteMessage();}}, 400));});} else {return;}});}, 1000 * 20);}//二、白天快速版本(得盯着点)--------------------------------------------------------------------------------------------------------------------------------
{function deleteMessage() {try {var scroHeight = 700; //向下滑动的高度 px// 更多按钮let iDom = document.getElementsByClassName('woo-font woo-font--angleDown morepop_action_bk3Fq')[0];if (iDom) {//先找到当前博文var currentcontext = iDom.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;//一、蓝色警方通告var tonggao = currentcontext.getElementsByClassName('woo-box-flex woo-box-alignCenter woo-box-justifyCenter woo-tip-main woo-tip-flat woo-tip-warn tips_tip_3WqKM tips_cursor_2uylm')[0];if (tonggao)//找到当前通告的话,删除当前整个博文,并return,并向下滑动{//根据通告框找到当前最高级别(用于删除)var tonggaoParent = tonggao.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;//1、先删除自己tonggaoParent.parentNode.removeChild(tonggaoParent);//2、再向下滑动window.scrollBy({top: scroHeight,behavior: 'smooth' // 可选,使滚动平滑进行});return;}//二、黄色举报通告var jubao = currentcontext.getElementsByClassName('woo-box-flex woo-box-alignCenter woo-box-justifyCenter woo-tip-main woo-tip-flat woo-tip-error tips_tip_3WqKM tips_cursor_2uylm')[0];if (jubao)//找到当前通告的话,删除当前整个博文,并return,并向下滑动{//根据通告框找到当前最高级别(用于删除)var tonggaoParent = jubao.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;//1、先删除自己tonggaoParent.parentNode.removeChild(tonggaoParent);//在向下滑动window.scrollBy({top: scroHeight,behavior: 'smooth' // 可选,使滚动平滑进行});return;}当前博文做屏幕居中操作获取元素相对于视口的位置//var elementRect = iDom.getBoundingClientRect();计算滚动位置//var offsetTop = elementRect.top + window.scrollY - (window.innerHeight / 2) + (elementRect.height / 2);滚动到指定位置//window.scrollTo({// top: offsetTop,// behavior: 'smooth'//});iDom.scrollIntoView({behavior: 'smooth',block: 'center',inline: 'center'});iDom.click();setTimeout(() => {let deleteOptions = document.getElementsByClassName('woo-box-flex woo-box-alignCenter woo-pop-item-main');// 循环更多列表内的按钮for (let option of deleteOptions) {// 只对删除按钮点击if (option.textContent.trim() == '删除' || option.textContent.trim() == '取消快转') {option.click();setTimeout(() => {// 等待删除对话框出现后再点击确定按钮var dialogCtrl = document.querySelector('.woo-dialog-ctrl');if (dialogCtrl) {// 删除弹窗的确定按钮var secondButton = dialogCtrl.querySelectorAll('button')[1].click();console.log("删除成功了");setTimeout(() => {// 递归调用此方法deleteMessage();}, 200);}}, 200);break;}}}, 100);}} catch (error) {// 异常捕获console.error("郭哥报错了!:", error);}}setInterval(deleteMessage, 200); //var timers = setInterval(function () {// //怕有空白处可能导致js不执行,所以刷新一下微博列表// var buttons = document.querySelectorAll('.Profile_btn_4Wj2Q');// if (buttons.length > 1) {// buttons[1].click();// 点击第二个按钮“微博”// } else {// return;// }// setInterval(deleteMessage, 200); //}, 1000 * 20);}