Greasy Fork is available in English.
try to take over the world!
当前为
// ==UserScript==
// @name 虎扑网红鬼畜表情图屏蔽缩小
// @namespace http://tampermonkey.net/
// @version 0.7
// @license MIT
// @description try to take over the world!
// @author You
// @match https://bbs.hupu.com/*.html
// @match https://m.hupu.com/bbs/*.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==
//用户添加自己要屏蔽或者缩小的图片的url,用images.push加一行
let imageMap = new Map();
let images = [];
images.push("https://i4.hoopchina.com.cn/hupuapp/bbs/659/26124659/thread_26124659_20220502102437_s_2861733_o_w_576_h_768_69592.gif");
images.push("https://i5.hoopchina.com.cn/hupuapp/bbs/109/37338109/thread_37338109_20210220183736_s_5420718_o_w_550_h_550_29803.gif");
images.push("https://i4.hoopchina.com.cn/hupuapp/bbs/0/0/thread_0_20220716191215_s_89079_o_w_440_h_440_62625.jpg");
images.push("https://i3.hoopchina.com.cn/hupuapp/bbs/0/0/thread_0_20220731165903_s_25909_o_w_810_h_595_79234.jpg");
images.push("https://i5.hoopchina.com.cn/hupuapp/bbs/268/27421268/thread_27421268_20220317112134_s_101479_w_855_h_861_74144.jpg");
images.push("https://i10.hoopchina.com.cn/hupuapp/bbs/762/48837762/thread_48837762_20210602234639_s_209846_w_464_h_483_18974.png?x-oss-process=image/resize,w_225/qulity,Q_60");
images.push("https://i1.hoopchina.com.cn/hupuapp/bbs/79/25409079/thread_25409079_20220528082159_s_77155_w_246_h_246_77938.png?x-oss-process=image/resize,w_225/qulity,Q_60");
images.push("https://i4.hoopchina.com.cn/hupuapp/bbs/111111/thread_111111_20220527134517_s_10151_w_196_h_172_66941.jpg?x-oss-process=image/resize,w_225/qulity,Q_60");
images.push("https://i3.hoopchina.com.cn/newsPost/rc-upload-1675337463596-4/1675337542711-92bcc207.jpg");
images.push("https://i3.hoopchina.com.cn/newsPost/rc-upload-1675337463596-2/1675337537456-80e2c558.jpg");
images.push("https://i2.hoopchina.com.cn/hupuapp/bbs/3/thread_3_20230109235917_s_1876759_o_w_289_h_288_30392.gif?x-oss-process=image/resize,w_800/format,webp");
images.push("https://i11.hoopchina.com.cn/reply/1676087734070-0544231e-8490-4739-af07-b2c8d5f58ea5.gif?x-oss-process=image/resize,w_800/format,webp");
let blacklist = new Set();
let blacklist2 = new Set();
let isPC = true;
function initImageMap() {
for (let image of images) {
let pIndex = image.indexOf("?");
if (pIndex > -1) {
image = image.substring(0, pIndex);
}
let id = "";
let index = image.indexOf("thread_");
if (index > -1) {
for (let i = index + 7; i < image.length; i++) {
if (image[i] >= 'a' && image[i] <= 'z') {
break;
}
id += image[i];
}
} else {
let splits = image.split("/");
let name = splits[splits.length - 1];
let split2 = name.split(".");
id = split2[0];
}
imageMap.set(id, image)
}
}
function updateBlackList() {
let checkIds = GM_getValue("checked_ids", new Set());
blacklist = new Set();
for (let id of checkIds) {
if (imageMap.has(id)) {
blacklist.add(id);
}
}
}
function updateBlackList2() {
let checkIds = GM_getValue("checked_ids2", new Set());
blacklist2 = new Set();
for (let id of checkIds) {
if (imageMap.has(id)) {
blacklist2.add(id);
}
}
}
(function () {
'use strict';
let url = window.location.href;
if (url.includes("m.hupu.com")) {
isPC = false;
} else {
isPC = true;
}
initImageMap();
updateBlackList();
updateBlackList2();
GM_registerMenuCommand("图片屏蔽", setting, "");
GM_registerMenuCommand("图片缩小", setting2, "");
let parentClass = ".post-reply-list";
if (!isPC) {
parentClass = ".hp-m-post-page";
}
$(document).ready(function () {
$(parentClass).each(function (i, e) {
removeImg(e);
$(e).bind("DOMNodeInserted", function () {
removeImg(e);
})
})
});
})();
//e是.image-wrapper
function removeImg(e) {
let imgClass = ".thread-img";
let imgParent = ".image-wrapper";
if (!isPC) {
imgClass = "img.hupu-fufu-lazy-img";
imgParent = ".discuss-card__images"
}
$(e).find(imgClass).each(function (i2, e2) {
let src = $(e2).attr("src");
for (let black of blacklist) {
if (src.includes(black)) {
$(e2).parents(imgParent).first().remove();
break;
}
}
for (let black of blacklist2) {
if (src.includes(black)) {
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: auto;overflow-x:hidden;z-index: 9999;position: fixed;padding:5px;text-align:center;width: 175px;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 id=\"z_table\" border=\"0\" style=\"width: 100%;border-collapse:collapse;\">\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" +
" <HR align=center width=300 color=#987cb9 SIZE=1/>\n" +
" </tr>\n" +
" </table>\n" +
"</div>");
for (let key of imageMap.keys()) {
let value = imageMap.get(key);
let tr = `<tr>\n' +
' <td style="width: 200px;"><input type="checkbox" id="${key}" class="hp-cbx"/></td>\n' +
' <td><img src="${value}" height="50px"/>\n' +
' </tr>\n' +
' <tr>`
$("#z_table").append(tr)
}
let divStyle = $("#setting1").attr("style");
if (isPC) {
divStyle = divStyle + ";max-height: 800px;"
} else {
divStyle = divStyle + ";max-height: 600px;"
}
$("#setting1").attr("style", divStyle);
$("#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);
}
}