批量删除微博的方法

启发来自 http://vitovan.github.io/Weibored.js/

实际上,可以稍微修改一下使用 @require 来加载 jQuery,至少在 FireFox 下是可用的:

// @require https://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js

其实,可以完全不用 jQuery:

// ==UserScript==
// @name         Weibored.js
// @namespace    http://vito.sdf.org
// @version      0.1
// @description  删除所有微博
// @author       Vito Van
// @match        http://weibo.com/p/*
// @grant        none
// ==/UserScript==
for (var i = 0; i < 100; i++) {
  setTimeout(function () {
    document.querySelector('a[action-type="fl_menu"]').click();
    document.querySelector('a[title="删除此条微博"]').click();
    document.querySelector('a[action-type="ok"]').click();
    window.scrollTo(0, document.body.scrollHeight);
  }, 1000 * i);
}

删除发出的评论

使用 FireFox Remote Control 这个 add-on。

开启后可以通过 telnet 控制 FireFox。

下面我们使用 Ruby 来控制 Telnet。

这个可以用来删除微博上发出的评论。然而需要注意的是,由于新浪系统本身不可靠(删除了之后页面数量不等量变少),所以这样跑一遍也有可能也不够。

require "net/telnet"

firefox = Net::Telnet::new("Host" => "localhost", "Port" => 32000, "Prompt" => /\n/)

200.downto(1) do |i|
  puts firefox.cmd("document.location = 'http://weibo.com/comment/outbox?page=#{i}'")
  sleep 3

  (1..30).each do
    result = firefox.cmd(%Q|document.querySelector('a[action-type="delComment"]').click();|)

    if result =~ /error/
      break
    end
    
    sleep 0.5
    firefox.cmd(%Q|document.querySelector('a[action-type="ok"]').click();|)
    sleep 1
  end
end