// ==UserScript== // @name 虎扑网红鬼畜表情图屏蔽缩小 // @namespace http://tampermonkey.net/ // @version 0.9 // @license MIT // @description 去tm的鬼畜网红图,摸鱼万岁 // @author zwxbest // @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 // @require https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js // @resource bootstrap https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css // @grant GM_addStyle // @grant GM_getResourceText // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @downloadURL none // ==/UserScript== 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; let GM_KEY_SHOW_IMAGE = "show_image_urls"; let GM_KEY_BLOCK_ID = "block_ids"; let GM_KEY_SMALL_ID = "small_ids"; let GM_KEY_BLOCK_ALL = false; class Menu { constructor(name, func, id) { this.name = name; this.func = func; this.id = id; } } let menus = []; menus.push(new Menu("🚫图片屏蔽", setting, -1)); menus.push(new Menu("🐌图片缩小", setting2, -1)); menus.push(new Menu("➕添加屏蔽图", setting3, -1)); menus.push(new Menu("❌屏蔽全站图片", setting5, -1)); menus.push(new Menu("❗重置", setting4, -1)); (function () { 'use strict'; registerMenu(); let blockAll = GM_getValue(GM_KEY_BLOCK_ALL, false); if (blockAll) { $(document).ready(function () { $(document).bind("DOMNodeInserted", function () { $("img").attr("hidden", true); }) }); } else { var bootCSS = GM_getResourceText("bootstrap"); GM_addStyle(bootCSS); let url = window.location.href; isPC = !url.includes("m.hupu.com"); initImageMap(); updateBlackList(); updateBlackList2(); let parentClass = isPC ? ".post-reply-list" : ".hp-m-post-page"; $(document).ready(function () { $(parentClass).each(function (i, e) { removeImg(e); $(e).bind("DOMNodeInserted", function () { removeImg(e); }) }) }); } })(); function registerMenu() { let blockAll = GM_getValue(GM_KEY_BLOCK_ALL, false); if (blockAll) { menus[3].name = "✔已屏蔽全站图片" } for (let m of menus) { m.id = GM_registerMenuCommand(m.name, m.func, ""); } } function initImageMap() { let showImage = GM_getValue(GM_KEY_SHOW_IMAGE, []); if (showImage.length === 0) { GM_setValue(GM_KEY_SHOW_IMAGE, images); } let allIamges = GM_getValue(GM_KEY_SHOW_IMAGE, []); for (let image of allIamges) { let idImage = getImageAndId(image); imageMap.set(idImage[0], idImage[1]); } console.log(allIamges); console.log(imageMap); } function getImageAndId(image) { let id = "";//如果url中没有找到标识字符串,用乱码代替,这样不会匹配任何图片 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("/"); for(let split of splits){ if (split.includes(".jpg") || split.includes(".jpeg") || split.includes(".png") || split.includes(".gif")) { let split2 = split.split("."); id = split2[0]; break; } } } id = id === "" ? "@1pgCMxYJk*t_" : id; return [id, image]; } function updateBlackList() { let checkIds = GM_getValue(GM_KEY_BLOCK_ID, new Set()); blacklist = new Set(); for (let id of checkIds) { if (imageMap.has(id)) { blacklist.add(id); } } } function updateBlackList2() { let checkIds = GM_getValue(GM_KEY_SMALL_ID, new Set()); blacklist2 = new Set(); for (let id of checkIds) { if (imageMap.has(id)) { blacklist2.add(id); } } } //e是.image-wrapper function removeImg(e) { let imgClass = isPC ? ".thread-img" : "img.hupu-fufu-lazy-img"; let imgParent = isPC ? ".image-wrapper" : ".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(GM_KEY_BLOCK_ID, [])); if (checked) { checkIds.add(id); } else { checkIds.delete(id); } GM_setValue(GM_KEY_BLOCK_ID, Array.from(checkIds)); updateBlackList(); } function selectCheckbox2(e) { let checked = e.checked; let id = $(e).attr("id"); let checkIds = new Set(GM_getValue(GM_KEY_SMALL_ID, [])); if (checked) { checkIds.add(id); } else { checkIds.delete(id); } GM_setValue(GM_KEY_SMALL_ID, Array.from(checkIds)); updateBlackList2(); } function setting() { // 初始化打开开关 addUI(); let checkIds = new Set(GM_getValue(GM_KEY_BLOCK_ID, [])); 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() { clearUI(); $("body").append("
全选 \n" +
" | \n" +
" \n" + " | \n" + " |