百度删帖管理

try to take over the world!

当前为 2020-11-14 提交的版本,查看 最新版本

// ==UserScript==
// @name         百度删帖管理
// @namespace    http://tampermonkey.net/
// @version      0.3
// @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(getCookie("hideDeleted")) || 0;
    let hideSaving = Number(getCookie("hideSaving")) || 0;
    let hideList = JSON.parse(getCookie("hideList")) || [];
    debug && console.log(getCookie("hideList"));
    debug && console.log(hideList);

    function addCookie(objName, objValue, objDays) { // objDays = 不填/数字/Infinity
        let str = objName + "=" + escape(objValue);
        if (objDays > 0) {
            let date = new Date();
            let ms = objDays * 24 * 3600 * 1000;
            date.setTime(date.getTime() + ms);
            str += "; expires=" + date.toGMTString();
        }
        if (objDays === Infinity) {
            str += "; expires=Fri, 31 Dec 9999 23:59:59 GMT";
        }
        str += "; path=/";
        document.cookie = str;
    }

    function getCookie(name) {
        let arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if ((arr = document.cookie.match(reg))) {
            return unescape(arr[2]);
        } else {
            return null;
        }
    }

    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) > -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) {
                        let tr = $(e.target).parent().parent();
                        let content = tr.find("td.pm_recycle_content span").html().trim();
                        let info = tr.find("tr").eq(4).html();
                        hideList.push(content);
                        debug && console.log(JSON.stringify(hideList));
                        debug && console.log(unescape(JSON.stringify(hideList)));
                        addCookie("hideList", JSON.stringify(hideList), Infinity);
                        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) {
        addCookie("hideDeleted", e.target.checked ? 1 : 0, Infinity);
        location.reload();
    });
    $("#hideSaving").off("click").on("click", function (e) {
        addCookie("hideSaving", e.target.checked ? 1 : 0, Infinity);
        location.reload();
    });
    $("#doHide").off("click").on("click", function (e) {
        doHide();
    });
    doHide();
})();