屏蔽虎扑网红表情图

try to take over the world!

目前为 2023-02-12 提交的版本。查看 最新版本

// ==UserScript==
// @name         屏蔽虎扑网红表情图
// @namespace    http://tampermonkey.net/
// @version      0.3
// @license       MIT
// @description  try to take over the world!
// @author       You
// @match        https://bbs.hupu.com/*.html
// @icon         https://www.google.com/s2/favicons?sz=64&domain=hupu.com
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @require      https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js


// ==/UserScript==
//用户添加自己要屏蔽的,放到initBlacklist中
// 比如这张图,https://i3.hoopchina.com.cn/hupuapp/bbs/0/0/thread_0_20220731165903_s_25909_o_w_810_h_595_79234.jpg?x-oss-process=image/resize,w_225/qulity,Q_60,
// 取thread_后面的两串数字,0_20220731165903,加到initBlacklist,变成
// let initBlacklist = ["0_20220731165903"];

let initBlacklist = [];

let imageMap = new Map();
imageMap.set("img1", "26124659_20220502102437");
imageMap.set("img2", "37338109_20210220183736");

let blacklist = new Set();

function updateBlackList() {
    let checkIds = GM_getValue("checked_ids", new Set());
    blacklist = new Set(initBlacklist);
    for (let id of checkIds) {
        let hpid = imageMap.get(id);
        if (hpid) {
            blacklist.add(hpid);
        }
    }
}

(function () {
    'use strict';
    updateBlackList();
    GM_registerMenuCommand("打开设置", setting, "h");

    $(document).ready(function () {
        $('.post-reply-list').each(function (i, e) {
            //console.log(e);
            removeImg(e);
            $(e).bind("DOMNodeInserted", function () {
                removeImg(e);
            })
        })
    });
})();

//e是.image-wrapper
function removeImg(e) {
    $(e).find(".thread-img").each(function (i2, e2) {
        let src = $(e2).attr("src");
        for (let black of blacklist) {
            if (src.includes(black)) {
                $(e2).parents(".image-wrapper").first().remove();
                break;
            }
        }
    });
}

function selectCheckbox(e) {
    let checked = e.checked;
    let id = $(e).attr("id");
    let checkIds = new Set(GM_getValue("checked_ids", []));
    if (checked) {
        checkIds.add(id);
    } else {
        checkIds.delete(id);
    }
    GM_setValue("checked_ids", Array.from(checkIds));
    updateBlackList();
}

function setting() {
    // 初始化打开开关
    $("body").append("<div style='right: 10px;top: 100px;background: #f8f8f8;color:#ffffff;overflow: hidden;z-index: 9999;position: fixed;padding:5px;text-align:center;width: 175px;max-height: 600px;border-radius: 4px;border-style:solid;\n" +
        " border-width:1px; border-color:black;'>\n" +
        "    <div style=\"margin-bottom: 20px\"><span style=\"color:black;\">选择要屏蔽的图</span></div>\n" +
        "    <table border=\"0\" style=\"width: 100%;\">\n" +
        "        <tr>\n" +
        "            <td style=\"width: 200px;\"><input type=\"checkbox\" id=\"img1\" class=\"hp-cbx\"/></td>\n" +
        "            <td><img src=\"https://i.328888.xyz/2023/02/11/RqAOA.jpeg\" height=\"100px\"/>\n" +
        "        </tr>\n" +
        "        <tr>\n" +
        "            <HR align=center width=300 color=#987cb9 SIZE=1/>\n" +
        "        </tr>\n" +
        "        <tr>\n" +
        "            <td style=\"width: 200px;\"><input type=\"checkbox\" id=\"img2\" class=\"hp-cbx\"/></td>\n" +
        "            <td><img src=\"https://i.328888.xyz/2023/02/11/RqDeo.jpeg\" height=\"100px\"/>\n" +
        "        </tr>\n" +
        "    </table>\n" +
        "</div>");
    let checkIds = new Set(GM_getValue("checked_ids", []));
    $(".hp-cbx").each(function (i, e) {
        $(e).click(function () {
            selectCheckbox(this)
        })
        let id = $(e).attr("id");
        if (checkIds.has(id)) {
            $(e).prop("checked", true);
        }
    })
}