我今天突发奇想把想把新浪微博上发过的内容全部删除了,就找了一个脚本,挺方便的,用了将近20分钟把六千多条微博全部del了。。。

脚本是由 TibcoPaul同学写的,很方便基本没有中断,脑袋抽风想删除自己微博的童鞋可以试试~~

// 使用方法:
// 1. 先进入你的个人主页
// 2. 在Firefox控制台或者Chrome控制台执行这段代码
// 3. 等待, 直到页面弹出"It's done! Love you! Tibco Paul."

var deleteAllMyPost = function() {
    // check browser
    if (!document.createEvent) {
        alert('Sorry, but you should run my script under Firefox or Chrome, NO IE!nn对不起, 你只能在火狐或者谷歌浏览器Chrome下运行这段代码!nnTo download Firefox, please go to: "http://www.mozilla.org/en-US/firefox/new/", then install "Firebug" to run it;nn下载火狐,请打开:http://www.mozilla.org/en-US/firefox/new/');
        return false;
    } 

    // seriously warning!
    var dbconfirm = confirm('Warning: to run this script, all of your posts in Weibo.com will be deleted! ARE YOU SURE?nn警告: 如果继续执行这个代码, 那么你新浪微博里面的所有的帖子都会被删除, 你确定么?');

    if (!dbconfirm) {
        return false;
    }

    // check if current page is personal page
    var pageUrl = location.href;
    if (!/.*/profile?.*/.test(pageUrl)) {
        alert('Sorry, but, to run this script to delete your all of your posts, you should go to your personal page by clicking your avatar or your nic-name next to your avatar;nn对不起, 要运行这段代码去删除你所有的新浪微博帖子, 请点击你的头像或者你头像旁边的你的昵称跳到你的个人微博主页.');
        return false;
    }

    // deleting indicator
    var masker = document.createElement('div');
    var maskerText = '<h1>Deleting all posts of your weibo.com, to cancel deleting, please press F5 key. <br /> 正在删除新浪微博所有的帖子,如果要停止删除,请按 F5 键.</h1>';
    masker.innerHTML = maskerText;
    masker.style.opacity = '0.7';
    masker.style.backgroundColor = '#000000';
    masker.style.position = 'fixed';
    masker.style.height = '100%';
    masker.style.width= '100%';
    masker.style.top= '0';
    masker.style.left= '0';
    masker.style.zIndex= '9999';
    masker.style.color= '#ffffff';
    masker.style.padding= '100px';

    document.body.appendChild(masker);

    // prepare click event
    var event = document.createEvent('HTMLEvents');
    event.initEvent('click', true, true);

    // get next page handler
    var getNextPageBtn = function() {
        var tmpBtns = document.getElementsByTagName('span');
        len = tmpBtns .length;
        window.nextPageBtn = null;
        for (var i = 0; i < len; i++) {
            nextPageBtnTmp = tmpBtns[i];
            if (/下一页/.test(nextPageBtnTmp.innerHTML)){
                nextPageBtn = nextPageBtnTmp.parentNode;
            }
        }
        return nextPageBtn;
    }

    // periodly check next page button is available

    // trigger lazyload to load all post
    // trigger
    // scroll down to trigger lazyLoad

    var scrollDown = function() {
        setInterval(function(){
            // if pre-cached nextPageBtn is removed from dom, then rock it again
            getNextPageBtn();
            if (!nextPageBtn || !nextPageBtn.parentNode.parentNode) {
                var sh = document.body.scrollHeight;
                window.scroll(0, sh);
                // if failed, retry
                var retryLoadLinkTmp = document.getElementsByTagName('a');
                len = retryLoadLinkTmp.length;
                for (var i = 0; i < len; i++) {
                    var retryLoadLink = retryLoadLinkTmp[i];
                    if (/请重试/.test(retryLoadLink.innerHTML)){
                        retryLoadLink.dispatchEvent(event);
                    }
                }
            } else if (typeof countActiveXhr == 'undefined' || countActiveXhr === 0) {
                main();
            }
        }, 1000);
    }

    // invoke scrollDown
    scrollDown();

    var main = function() {

        // all array or dom obj len
        var len = 0;

        // new get all dl list, the post id is attached on dl element
        var elements = document.getElementsByTagName('dl');
        var myE = null;
        // all post id (message id) to delete
        var midToDel = [];

        // filter dl that doesn't have feed_list_item attribute
        var dlAttrFileter = '';

        // catch all dom obj to array, speed up javascript
        var elementArr = [];

        len = elements.length;
        for (var i = 0; i < len; i++ ) {
            elementArr[i] = elements[i];
        }

        len = elementArr.length;
        for (var i = 0; i < len; i++) {
            myE = elementArr[i];
            dlAttrFileter = myE.getAttribute('action-type');
            // if has action-type attribute and it's value is equal to feed_list_item
            if (dlAttrFileter && (dlAttrFileter == 'feed_list_item')) {
                // push all post id in midToDel array
                midToDel.push(myE.getAttribute('mid'));
            }
        }

        var xhrs = [];
        // count current active xhr, if none active, then turn to next page
        window.countActiveXhr = 0;

        len = midToDel.length;
        for (var i = 0; i < len; i++) {
            // create new xhr
            xhrs[i] = new XMLHttpRequest();
            xhrs[i].open('POST', 'http://weibo.com/aj/mblog/del');
            // should set these headers, to simulate the xhr is generated by native script in weibo.com
            xhrs[i].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
            xhrs[i].setRequestHeader('X-Requested-With', 'XMLHttpRequest');
            xhrs[i].onreadystatechange = function() {
                if (this.readyState == 4 && (this.status == 200)) {
                    // decreate the active xhr counter
                    countActiveXhr--;
                    if (!countActiveXhr) {
                        // turn to next page, fire click event
                        nextPageBtn.dispatchEvent(event);
                    }
                }
            };
            // send data, keep in mind, the _t is extra data required by weibo.com
            xhrs[i].send('mid=' + midToDel[i] + '&' + '_t=0');

            // increate active xhr counter
            countActiveXhr++;
        }
    }

}

// rock it!!!!
deleteAllMyPost();
————————————————————分——————割———————线——————————————————————————

PS:新浪微博的比较顽固所以要这么删,我这里再给出饭否和twitter的批量删除方法 (这两个都是利用oauth登录后通过api删除的,很安全)

饭否 http://marcher.sinaapp.com

twitter http://app.orzdream.com/twitrub/