百度删帖管理

try to take over the world!

目前为 2021-02-23 提交的版本。查看 最新版本

// ==UserScript==
// @name         百度删帖管理
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  try to take over the world!
// @author       You
// @match        *tieba.baidu.com/pmc*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    // debug模式
    let debug = false;
    // 自动填充话术
    let autoInfo = "该内容没有任何违反《百度贴吧协议》的信息,烦请恢复!";
    // 是否隐藏已删除
    let hideDeleted = localStorage.getItem("hideDeleted") || "";
    // 是否隐藏恢复中
    let hideSaving = localStorage.getItem("hideSaving") || "";
    // 已删除列表(取本地)
    let hideList = JSON.parse(localStorage.getItem("hideList")) || [];
    debug && (console.log(localStorage.getItem("hideList")) || console.log(hideList));

    // 自动跳转到系统删帖
    if (window.location.href.split("?")[0].endsWith("pmc")) {
        window.location.href = "/pmc/recycle?tab=system";
        return;
    }

    // 添加页面按钮
    let btn1 = "<input id='hideDeleted' type='checkbox' " + (hideDeleted ? "checked" : "") + "/>隐藏已删除";
    let btn2 = "<input id='hideSaving' type='checkbox' " + (hideSaving ? "checked" : "") + "/>隐藏恢复中";
    let btn3 = "<input id='doHide' type='button' value='隐藏'/>";
    $("div.panel_notice").after("<div class='panel_notice'>" + btn1 + "&nbsp;" + btn2 + "&nbsp;" + btn3 + "</div>");
    $("#hideDeleted").off("click").on("click", function (e) {
        localStorage.setItem("hideDeleted", e.target.checked ? "1" : "");
        location.reload();
    });
    $("#hideSaving").off("click").on("click", function (e) {
        localStorage.setItem("hideSaving", !!e.target.checked ? "1" : "");
        location.reload();
    });
    $("#doHide").off("click").on("click", function (e) {
        location.reload();
    });

    let eventId = setInterval(function () {
        // 监听页面是否加载完
        if (!$("span.del-reason-sty").length) {
            return;
        }
        clearInterval(eventId);

        $("span.pm_post_content").each(function (i, o) {
            // 申请状态节点
            let applyStateNode = $(o).parent().next().next().next();
            // 整行
            let wholeLine = $(o).parent().parent();
            // 删帖时间
            let deleteTime = $(o).parent().next().next().html();
            // 隐藏恢复中
            if (hideSaving && applyStateNode.html().includes("等待人工恢复")) {
                wholeLine.html(`<td class='pm_recycle_content' colspan='6' style='height:20px;color:grey;'>此条消息等待恢复中 (${deleteTime})</td>`);
            }
            // 隐藏已删除
            if (hideDeleted && hideList.some(oo => $(o).html().includes(oo.trim()))) {
                wholeLine.html(`<td class='pm_recycle_content' colspan='6' style='height:20px;color:grey;'>此条消息主楼已删除 (${deleteTime})</td>`);
            }
            // 修改申请按钮
            let applyBtn = applyStateNode.find("a.delpost_recover"), url;
            if (applyBtn.length) {
                url = applyBtn[0].href;
                applyBtn[0].outerHTML = `<a href='javascript:void(0);' target="_blank" class="delpost_recover apply_for_recover_tip">${applyBtn[0].innerHTML}</a>`;
            }
            // 自动提交申请
            applyStateNode.find("a.delpost_recover").off("click").on("click", function () {
                let newWindow = window.open(url, "_blank");
                let startApply = 0, autoFill = 0, autoSubmit = 0;
                let event = setInterval(function () {
                    let textArea = newWindow.document.getElementsByClassName("j_textarea");
                    let normalBtn = newWindow.document.getElementsByClassName("tm_normal_btn");
                    let errorTip = newWindow.document.getElementsByClassName("j_error_tip");
                    let big = newWindow.document.getElementsByClassName("p_big");
                    if (textArea.length === 1 && autoFill === 0) {
                        autoFill = 1;
                        textArea[0].innerHTML = autoInfo;
                        newWindow.document.getElementsByClassName("j_submit")[0].click();
                    } else if (normalBtn.length === 1 && startApply === 0) {
                        startApply = 1;
                        normalBtn[0].click();
                    } else if (autoFill === 1 && autoSubmit === 0) {
                        if (errorTip.length === 1 && errorTip[0].innerHTML.includes("今天已达到恢复上限")) {
                            autoSubmit = 1;
                        } else if (big.length === 1 && $(big[0]).parent().css("display") != "none") {
                            autoSubmit = 1;
                            clearInterval(event);
                            newWindow.close();
                        }
                    }
                }, 100);
            });
            // 添加手动删除按钮
            applyStateNode.find("br").length || $("<a href='javascript:void(0);'>将此条标记为删除</a>").on("click", function (e) {
                if (!confirm("确定删除?")) {
                    return;
                }
                let tr = $(e.target).parent().parent();
                let content = tr.find("td.pm_recycle_content span").html().trim();
                debug && console.log(content);
                hideList.push(content);
                debug && console.log(JSON.stringify(hideList));
                localStorage.setItem("hideList", JSON.stringify(hideList));
                !debug && location.reload();
            }).appendTo(applyStateNode.append("<br/>"));
        });
    }, 100);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址