百度删帖管理

try to take over the world!

目前為 2020-12-04 提交的版本,檢視 最新版本

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

(function () {
    'use strict';
    let debug = false;
    let url = window.location.href.split("?")[0];
    if (url.length === url.indexOf("pmc") + 3) {
        window.location.href = "http://tieba.baidu.com/pmc/recycle?tab=system";
    }
    let hideDeleted = Number(localStorage.getItem("hideDeleted")) || 0;
    let hideSaving = Number(localStorage.getItem("hideSaving")) || 0;
    let hideList = JSON.parse(localStorage.getItem("hideList")) || [];
    debug && console.log(localStorage.getItem("hideList"));
    debug && console.log(hideList);

    function doHide() {
        let eventId = setInterval(function () {
            if ($("span.del-reason-sty").length) {
                clearInterval(eventId);
                $("span.pm_post_content").each(function (i, o) {
                    let info = $(o).parent().next().next().html();
                    if (hideSaving && $(o).parent().next().next().next().html().indexOf("等待人工恢复") > -1) {
                        $(o).parent().parent().html("<td class='pm_recycle_content' colspan='6' style='height:20px;color:grey;'>此条消息等待恢复中 (" + info + ")</td>");
                    }
                    if (hideDeleted && hideList.some(oo => $(o).html().indexOf(oo.trim()) > -1)) {
                        $(o).parent().parent().html("<td class='pm_recycle_content' colspan='6' style='height:20px;color:grey;'>此条消息主楼已删除 (" + info + ")</td>");
                    }
                    $(o).parent().next().next().next().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);
                        let info = tr.find("tr").eq(4).html();
                        hideList.push(content);
                        debug && console.log(JSON.stringify(hideList));
                        localStorage.setItem("hideList", JSON.stringify(hideList));
                        !debug && location.reload();
                    }).appendTo($(o).parent().next().next().next().append("<br/>"));
                });
            }
        }, 100);
    }

    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 : 0);
        location.reload();
    });
    $("#hideSaving").off("click").on("click", function (e) {
        localStorage.setItem("hideSaving",e.target.checked ? 1 : 0);
        location.reload();
    });
    $("#doHide").off("click").on("click", function (e) {
        location.reload();
    });
    doHide();
})();