- 1.1 步骤
- 1.2 方案一:发起http请求,删除全部微博;
- 1.3 方案2: 利用action-type按钮事件删除微博
- 2.1 移除粉丝
- 2.2 移除关注
- 3.1 action-type 汇总
- 3.2 HTML DOM setInterval() :周期(以毫秒计)调用执行函数/表达式
- 4.1 编辑页面上的任何文本 ✍
- 4.2 Command 菜单
前言
本文的代码,在20210年7月11日时没有效果,因此才发布此文。分享本文的目的只为了交流技术。
先看下之前我测试的批量删除微博的效果
删除微博推荐使用本文1.2章节的方法,它是采用发起请求,具有安全且全自动的特点。
如果你只是不想被人看你之前的微博,可以设置最近半年可见就行
I、批量删除微博的方案
1.1 步骤
- 进入自己的微博主页(网页端)
- 将代码复制在 [ console ]目录 ,按回车键运行
- 如果出现错误,或者系统繁忙,就把代码在console 复制一遍
- 如果后悔了,想停止删除,就刷新页面即可(command +R / F5)
系统繁忙,是触发了风控机制,你稍后再试就行了
用法:
- 打开chrome的开发者工具:macOS下的快捷键是cmd+opt+i, windows是F12或者ctrl+shift+i)
- 点击Esc打开console,把代码粘贴进去,回车
1.2 方案一:发起http请求,删除全部微博;
支持自动刷新,滚动到最低部(触发自动加载微博)
- 完整代码
//删除本条微博 function del_weibo(id){ console.log(id); var postdata = "mid="+id; fetch("https://www.weibo.com/aj/mblog/del?ajwvr=6", { "credentials":"include", "headers":{ "content-type":"application/x-www-form-urlencoded", }, "referrer":"https://www.weibo.com", "body":postdata, "method":"POST","mode":"cors" }).then(response => console.log(response) ) .then(data => console.log(data)) .catch(error => console.log(error)); } //删除本页全部微博 function del_page(){ var wb_list = document.querySelectorAll(".S_txt2"); if(wb_list.length == 0){ console.log("暂无可删除微博"); } for(var t of wb_list){ if(t.name){ //限制请求速度 setTimeout(function(t) { del_weibo(t.name); var pppp_node = t.parentNode.parentNode.parentNode.parentNode; pppp_node.parentNode.removeChild(pppp_node); }, 1500,t); } } } // 刷新微博页面 function auto_update_page(){ var pages = document.querySelectorAll(".W_pages > a"); if(pages.length > 0){ var next_page = pages[pages.length-1]; console.log("下一页");//or上一页... next_page.click(); }else{ console.log(new Date().toLocaleTimeString() + ":加载中,请稍等"); window.scrollTo(0, 100000);//滚动到最低部(触发自动加载微博) } } function del_all_weibo(){ del_page(); auto_update_page();//尝试自动刷新 } // 定时执行删除 window.setInterval(del_all_weibo, 5000);
- 滚动到最低部(触发自动加载微博)
window.scrollTo(0, 100000);//滚动到最低部(触发自动加载微博) $('html, body').animate({ scrollTop: $(document).height() }, 'slow'); var len = $('div[action-type="feed_list_item"]').length; if (len < 5) { $('a[class="page next S_txt1 S_line1"]')[0].click(); }
1.3 方案2: 利用action-type按钮事件删除微博
利用Chrome的console删除所有微博:支持自动加载更多
// @description 删除所有微博 // ==/UserScript== 'use strict'; var s = document.createElement('script'); s.setAttribute( 'src', 'https://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js' ); s.onload = function() { setInterval(function() { if (!$('a[action-type="feed_list_delete"]')) { $('a.next').click(); } else { $('a[action-type="feed_list_delete"]')[0].click(); $('a[action-type="ok"]')[0].click(); } // scroll bottom let auto load $('html, body').animate({ scrollTop: $(document).height() }, 'slow'); var len = $('div[action-type="feed_list_item"]').length; if (len < 5) { $('a[class="page next S_txt1 S_line1"]')[0].click(); } }, 800); }; document.head.appendChild(s);
支持删除快转
'use strict'; var s = document.createElement('script'); s.setAttribute( 'src', 'https://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js' ); s.onload = function() { setInterval(function() { if ($('a[action-type="feed_list_delete_fast_reported"]')) { $('a[action-type="feed_list_delete_fast_reported"]')[0].click() } // if ($('a[action-type="fl_del_fast_reported"]')) { $('a[action-type="fl_del_fast_reported"]')[0].click() } if ($('a[action-type="feed_list_delete"]')) { $('a[action-type="feed_list_delete"]')[0].click() $('a[action-type="ok"]')[0].click() } $('a.next').click(); // scroll bottom let auto load $('html, body').animate({ scrollTop: $(document).height() }, 'slow'); var len = $('div[action-type="feed_list_item"]').length; if (len < 5) { $('a[class="page next S_txt1 S_line1"]')[0].click(); } }, 800); }; document.head.appendChild(s);
- 自动刷新当前页面
window.location.reload();
II、移除粉丝/关注的人
2.1 移除粉丝
应用场景:注销账户。
如果粉丝数达到一定的数目,那么在注销微博的最后一步,需要「把密码、注册地址」用邮件方式发到微博的客服邮箱。
var s = document.createElement('script'); s.setAttribute( 'src', 'https://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js' ); s.onload = function() { setInterval(function() { if (!$('a[action-type="removeFan"]')) { $('a.next').click(); } else { $('a[action-type="removeFan"]')[0].click(); setTimeout(function (){}, 50); $('a[action-type="ok"]')[0].click(); } var len = $('li.follow_item').length; if (len < 2) { $('a[class="page next S_txt1 S_line1"]')[0].click(); } }, 1500); }; document.head.appendChild(s);
- 移除微博数小于3的粉丝(僵死粉)
function removeFan() { fans = document.querySelectorAll("li[node-type=userItem]") console.log(fans.length) flag = false; for (var i = 0; i < fans.length; i++) { if (Number(fans[i].querySelectorAll("span em.count")[2].innerText) < 3) { // 移除微博数小于3的粉丝 fans[i].querySelector("a.tlink[action-type=removeFan]").click(); document.querySelector("a.W_btn_a[action-type=ok]").click(); flag = true; break; } } if (!flag) { clearInterval(timer); next = document.querySelector(".page.next.S_txt1.S_line1") if (next) {next.click(); setTimeout("timer = setInterval(removeFan, 1000);", 5000)} } } var timer = setInterval(removeFan, 1000);
2.2 移除关注
因为总是会莫名奇妙关注一些博主,当关注的达到一定数量之后,我就比较喜欢这个功能来移除一些关注
$(".btn_link.S_txt1").click(); // 进入“批量管理” // 选中全部 var lis = $(".member_li.S_bg1").parentNode.childNodes; for(var i=0;i<lis.length;i++){ lis[i].className = "member_li S_bg1 choosed S_link1_br"; } // 为了让“取消关注”可点击 $(".member_li.S_bg1").click();$(".member_li.S_bg1").click(); $(".W_btn_a[node-type='cancelFollowBtn']").click(); // 取消关注 $(".W_btn_a.btn_34px[node-type='ok']").click(); // 确定
III、利用action-type按钮事件删除微博的原理分析
利用关键词feed_list_delete
寻找要删除的微博类型
- feed_list_delete_fast_reported
- feed_list_delete
3.1 action-type 汇总
- feed_list_delete:删除
- fl_del_fast_reported 取消快转
- fl_reEdit:编辑微博
- fl_addTag :加标签
- fl_fansVisible:转换为粉丝可见
- fl_friendVisible:转换为好友圈可见
- fl_personalVisible:转换为仅自己可见
3.2 HTML DOM setInterval() :周期(以毫秒计)调用执行函数/表达式
setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式。
setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭。由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的参数。
- 语法
setInterval(code,millisec[,"lang"])
code :必须。要调用的函数或要执行的代码串。
millisec:必须。周期性执行或调用 code 之间的时间间隔,以毫秒计。
返回值:传递给 Window.clearInterval() 从而取消对 code 的周期性执行
- 例子:周期执行删除快转微博的函数,周期millisec为2000
'use strict'; var s = document.createElement('script'); s.setAttribute( 'src', 'https://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js' ); s.onload = function() { setInterval(function() { if ($('a[action-type="feed_list_delete_fast_reported"]')) { $('a[action-type="feed_list_delete_fast_reported"]').click() } // if ($('a[action-type="fl_del_fast_reported"]')) { $('a[action-type="fl_del_fast_reported"]').click() } if ($('a[action-type="feed_list_delete"]')) { $('a[action-type="feed_list_delete"]')[0].click() $('a[action-type="ok"]')[0].click() } $('a.next').click(); // scroll bottom let auto load $('html, body').animate({ scrollTop: $(document).height() }, 'slow'); }, 800); }; document.head.appendChild(s);
IV、Chrome DevTools中的操作技巧
Mac 使用 command+option+I 即可打开DevTools
4.1 编辑页面上的任何文本 ✍
在控制台输入document.body.contentEditable="true"
或者document.designMode = 'on'就可以实现对网页的编辑了。
如果你想快速修改一些网页数据,使用这个是最方便的,比什么P图软件都快
比如修改博客的总排名数据为1
Cmd + Shift + P
截图包含滚动条在内的所有页面内容
Capture full size screenshot(并不只是页面可视区域)
see aslo
- html进阶:【Meta 标签的 http-equiv 属性使用指南】