虎扑网红鬼畜表情图屏蔽缩小

try to take over the world!

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

// ==UserScript==
// @name         虎扑网红鬼畜表情图屏蔽缩小
// @namespace    http://tampermonkey.net/
// @version      0.4
// @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"];
//要缩小的图片的标识字符串,放到initBlacklist2中。

let initBlacklist = [];
let initBlacklist2 = [];

let imageMap = new Map();
imageMap.set("img1", "26124659_20220502102437");
imageMap.set("img2", "37338109_20210220183736");
imageMap.set("img3", "0_20220716191215");
imageMap.set("img4", "0_20220731165903");
imageMap.set("img5", "27421268_20220317112134");
imageMap.set("img6", "48837762_20210602234639");
imageMap.set("img7", "25409079_20220528082159");
imageMap.set("img8", "111111_20220527134517");

let blacklist = new Set();


let blacklist2 = 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 updateBlackList2() {
    let checkIds = GM_getValue("checked_ids2", new Set());
    blacklist2 = new Set(initBlacklist2);
    for (let id of checkIds) {
        let hpid = imageMap.get(id);
        if (hpid) {
            blacklist2.add(hpid);
        }
    }
    console.log("black list2");
    console.log(blacklist2);
}

(function () {
    'use strict';
    updateBlackList();
    updateBlackList2();
    GM_registerMenuCommand("图片屏蔽", setting, "");
    GM_registerMenuCommand("图片缩小", setting2, "");

    $(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;
            }
        }
        for (let black of blacklist2) {
            if (src.includes(black)) {
                console.log("缩小" + src);
                let style = $(e2).attr("style");
                $(e2).attr("style", style + "max-height:100px;")
                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 selectCheckbox2(e) {
    let checked = e.checked;
    let id = $(e).attr("id");
    let checkIds = new Set(GM_getValue("checked_ids2", []));
    if (checked) {
        checkIds.add(id);
    } else {
        checkIds.delete(id);
    }
    GM_setValue("checked_ids2", Array.from(checkIds));
    updateBlackList2();
}


function setting() {
    // 初始化打开开关
    addUI();
    let checkIds = new Set(GM_getValue("checked_ids", []));
    let allChecked = true;
    $(".hp-cbx").each(function (i, e) {
        $(e).click(function () {
            selectCheckbox(this)
        })
        let id = $(e).attr("id");
        if (checkIds.has(id)) {
            $(e).prop("checked", true);
        } else {
            allChecked = false;
        }
    })
    if (allChecked) {
        $("#z_all").prop("checked", true);
    }

}

function addUI() {
    $("#setting1").remove();
    $("#setting2").remove();
    $("body").append("<div id=\"setting1\" 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: 1000px;border-radius: 4px;border-style:solid;\n" +
        " border-width:1px; border-color:black;'>\n" +
        "    <div style=\"margin-bottom: 20px\"><span id=\"z_title\" style=\"color:black;\">选择要屏蔽的图</span></div>\n" +
        "    <table border=\"0\" style=\"width: 100%;\">\n" +
        "        <tr>\n" +
        "            <td style=\"width: 200px;\"><div style=\"color:black;\">全选</div>\n" +
        "                <input type=\"checkbox\" id=\"z_all\"/></td>\n" +
        "            <td style=\"width: 200px;\"></td>\n" +
        "        </tr>\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=\"60px\"/>\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=\"60px\"/>\n" +
        "        </tr>\n" +
        "        <tr>\n" +
        "            <td style=\"width: 200px;\"><input type=\"checkbox\" id=\"img3\" class=\"hp-cbx\"/></td>\n" +
        "            <td><img src=\"https://i.328888.xyz/2023/02/12/c0l3a.jpeg\" height=\"60px\"/>\n" +
        "        </tr>\n" +
        "        <tr>\n" +
        "            <td style=\"width: 200px;\"><input type=\"checkbox\" id=\"img4\" class=\"hp-cbx\"/></td>\n" +
        "            <td><img src=\"https://i.328888.xyz/2023/02/12/c0jQU.jpeg\" height=\"60px\"/>\n" +
        "        </tr>\n" +
        "        <tr>\n" +
        "            <td style=\"width: 200px;\"><input type=\"checkbox\" id=\"img5\" class=\"hp-cbx\"/></td>\n" +
        "            <td><img src=\"https://i.328888.xyz/2023/02/12/c0moZ.jpeg\" height=\"60px\"/>\n" +
        "        </tr>\n" +
        "        <tr>\n" +
        "            <td style=\"width: 200px;\"><input type=\"checkbox\" id=\"img6\" class=\"hp-cbx\"/></td>\n" +
        "            <td><img src=\"https://i.328888.xyz/2023/02/12/c0XjH.png\" height=\"60px\"/>\n" +
        "        </tr>\n" +
        "        <tr>\n" +
        "            <td style=\"width: 200px;\"><input type=\"checkbox\" id=\"img7\" class=\"hp-cbx\"/></td>\n" +
        "            <td><img src=\"https://i.328888.xyz/2023/02/12/c0g6Q.png\" height=\"60px\"/>\n" +
        "        </tr>\n" +
        "        <tr>\n" +
        "            <td style=\"width: 200px;\"><input type=\"checkbox\" id=\"img8\" class=\"hp-cbx\"/></td>\n" +
        "            <td><img src=\"https://i.328888.xyz/2023/02/12/c0xQE.jpeg\" height=\"60px\"/>\n" +
        "        </tr>\n" +
        "    </table>\n" +
        "</div>");

    $("#z_all").each(function (i, e) {
        $(e).click(function () {
            if (e.checked) {
                $(".hp-cbx").prop("checked", false);
            } else {
                $(".hp-cbx").prop("checked", true);
            }
            $(".hp-cbx").trigger("click");
        })
    })

    $("td").each(function (i, e) {
        let style = $(e).attr("style") ? $(e).attr("style") : "";
        $(e).attr("style", style + "border-bottom :1px solid black;")
    })
}

function setting2() {
    // 初始化打开开关
    addUI();
    $("#setting1").attr("id", "#setting2");
    $("#z_title").text("选择要缩小的图");
    let checkIds2 = new Set(GM_getValue("checked_ids2", []));

    let allChecked = true;

    $(".hp-cbx").each(function (i, e) {
        $(e).click(function () {
            selectCheckbox2(this)
        })
        let id = $(e).attr("id");
        if (checkIds2.has(id)) {
            $(e).prop("checked", true);
        } else {
            allChecked = false;
        }
    })
    if (allChecked) {
        $("#z_all").prop("checked", true);
    }
}