微博-批量删除微博

批量删除微博

目前为 2019-05-28 提交的版本。查看 最新版本

// ==UserScript==
// @name         微博-批量删除微博
// @namespace    https://www.jwang0614.top/scripts
// @version      0.1
// @description  批量删除微博
// @author       Olivia
// @match        https://weibo.com/*/profile*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...

    var delete_btn = createElement("p", "删除当前页面所有微博", "50px", "white", "30px", "20px 10px", "red", "fixed", "30px", "100px", "100000", "200px", "20px");
    var notice = createElement("p", "请将页面下拉到底端加载所有微博然后点击删除按钮", "20px", "black", "24px", "20px 10px", "white", "fixed", "30px", "300px", "100000", "200px", "");

    var container = document.querySelector('body');
    container.appendChild(delete_btn);
    container.appendChild(notice);

    delete_btn.onclick = function(){
        var posts = document.querySelectorAll(".WB_feed_detail");
        console.log(posts.length);
        var total_number = posts.length;

        if(confirm("确定删除当前页面上"+total_number+"条微博吗?")) {

            for (var i=0; i < total_number; i++) {
                console.log("index="+i);
                var post = posts[i];
                console.log(post);
                console.log(posts.length);

                var text = post.querySelector(".WB_text");
                console.log(text);

                var delete_post = post.querySelectorAll(".layer_menu_list li a")[0];
                console.log(delete_post);
                console.log(post);
                console.log("");
                delete_post.click();

                var confirm_btn = post.querySelectorAll(".layer_mini_opt .btn a")[0];
                console.log(confirm_btn);
                console.log(post);
                console.log("");
                confirm_btn.click();


            }


        }

    };


})();

function sleep (time) {
    return new Promise((resolve) => setTimeout(resolve, time));
}

function createElement(element_tag, textnode_str, lineheight, color, fontSize, padding, background, position, right, top, zIndex, width, borderRadius) {
    var ele = document.createElement(element_tag);
    ele.appendChild(document.createTextNode(textnode_str));
    ele.style.lineheight=lineheight;
    ele.style.color=color;
    ele.style.fontSize=fontSize;
    ele.style.padding=padding;
    ele.style.background=background;
    ele.style.position=position;
    ele.style.right=right;
    ele.style.top=top;
    ele.style.zIndex=zIndex;
    ele.style.width=width;
    ele.style.borderRadius = borderRadius;


    return ele;
}