Greasy Fork

Greasy Fork is available in English.

微博批量清理工具(XHR)

批量删除微博工具XHR版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         微博批量清理工具(XHR)
// @version      1.0.0
// @description  批量删除微博工具XHR版本
// @author       Tobar
// @match        *://weibo.com/u/*
// @grant        none
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js
// @require      https://cdn.bootcdn.net/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js
// @namespace http://greasyfork.icu/users/142679
// ==/UserScript==

(function () {
    'use strict';
    window.onload = () => {
        //睡眠函数
        function sleep(milliseconds) {
            var start = new Date().getTime();
            for (var i = 0; i < 1e7; i++) {
                if ((new Date().getTime() - start) > milliseconds) {
                    break;
                }
            }
        }

        function sendDelete(id) {
            var postData = {
                "id": id
            };
            var token = $.cookie("XSRF-TOKEN");
            console.info("token=" + token);
            $.ajax({
                url: "/ajax/statuses/destroy",
                contentType: "application/json;charset=UTF-8",
                type: "POST",
                dataType: "json",
                headers: {
                    "x-xsrf-token": token
                },
                data: JSON.stringify(postData)
            });
        }

        function deletePage(userId, pageNum) {
            var list;
            $.ajax({
                url: "/ajax/statuses/mymblog?uid=" + userId + "&page=" + pageNum + "&feature=0",
                type: "GET",
                //sync: false,
                dataType: "json"
            }).done(function (data, textStatus, jqXHR) {
                list = data;
                if (list != null && list.data != null && list.data.list != null) {
                    list.data.list.forEach(function (item) {
                        var id = item.id;
                        console.log(id);
                        sendDelete(id);
                        sleep(100);
                    });
                    sleep(1000);
                    deletePage(userId, pageNum + 1);
                }
            }).fail(function (jqXHR, textStatus, errorThrown) {
                var error = '状态码:' + jqXHR.status + ',异常:' + errorThrown;
                alert('读取数据失败,请稍后重试\n' + error);
            });

        }

        function startDelete() {
            //获取用户userid
            var userId;
            var patt = /weibo.com\/u\/(\d+)/i;
            var n = patt.exec(window.location.href);
            if (n != null && n.length > 1) {
                userId = n[1];
            }

            console.info("userId=" + userId);
            if (userId == null) {
                return;
            }
            deletePage(userId, 1);
        }

        var r = confirm("确定好要删除所有内容了吗,确定好了就点确定吧!");
        if (r === true) {
            startDelete();
        }

    };
})();