// ==UserScript== // @name 虎扑网红鬼畜表情图屏蔽缩小 // @namespace http://tampermonkey.net/ // @version 2.6 // @license MIT // @description 去tm的鬼畜网红图,摸鱼万岁 // @author zwxbest // @match https://bbs.hupu.com/*.html // @match https://m.hupu.com/bbs/* // @icon https://w1.hoopchina.com.cn/images/pc/old/favicon.ico // @require https://cdnjs.cloudflare.com/ajax/libs/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_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @connect gitee.com // @downloadURL https://update.greasyfork.icu/scripts/459844/%E8%99%8E%E6%89%91%E7%BD%91%E7%BA%A2%E9%AC%BC%E7%95%9C%E8%A1%A8%E6%83%85%E5%9B%BE%E5%B1%8F%E8%94%BD%E7%BC%A9%E5%B0%8F.user.js // @updateURL https://update.greasyfork.icu/scripts/459844/%E8%99%8E%E6%89%91%E7%BD%91%E7%BA%A2%E9%AC%BC%E7%95%9C%E8%A1%A8%E6%83%85%E5%9B%BE%E5%B1%8F%E8%94%BD%E7%BC%A9%E5%B0%8F.meta.js // ==/UserScript== let isPC = true; // 要屏蔽的图片,勾选中的才屏蔽 let GM_KEY_SHOW_IMAGE = "show_image_urls"; // 勾选中的图片id let GM_KEY_BLOCK_ID = "block_ids"; let GM_KEY_BLOCK_ALL = "block_all"; let GM_KEY_SMALL_ALL = "small_all" class Menu { constructor(name, func, id) { this.name = name; this.func = func; this.id = id; } } let curElemnt = null document.body.onmousemove = (event) => { curElemnt = event.target; }; let menus = []; menus.push(new Menu("➕添加屏蔽图", settingAdd, -1)); menus.push(new Menu("🚫图片屏蔽", settingSwitch, -1)); menus.push(new Menu("🐌缩小回复中的全部图片", settingSmall, -1)); menus.push(new Menu("❌屏蔽回复中的全部图片", settingBockAll, -1)); menus.push(new Menu("➰合并官方屏蔽图配置", settingRemote, -1)); menus.push(new Menu("❗重置", settingReset, -1)); function blockAllImage() { let classname = isPC ? ".reply-list-content img" : ".discuss-card__images"; $(classname).each(function (i, e) { let style = $(e).attr("style") ? $(e).attr("style") : ""; if (!style.includes("display:none;")) { $(e).attr("style", style + "display:none;"); } }) } function smallAllImage() { let classname = isPC ? ".reply-list-content img" : ".discuss-card__images img"; $(classname).each(function (i, e) { let style = $(e).attr("style") ? $(e).attr("style") : ""; if (!style.includes("max-height:80px;")) { $(e).attr("style", style + "max-height:80px;"); } }) } (function () { 'use strict'; registerMenu(); let url = window.location.href; isPC = !url.includes("m.hupu.com"); let blockAll = GM_getValue(GM_KEY_BLOCK_ALL, false); if (blockAll) { console.log("block all -------------") $(document).ready(function () { blockAllImage() var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { console.log(mutation.type) if (mutation.type === 'childList') { blockAllImage() } }); }); var config = { childList: true, attributes: true,subtree: true}; observer.observe(document, config); }); } else { var bootCSS = GM_getResourceText("bootstrap"); GM_addStyle(bootCSS); initShowImage(); let blockIds = getBlockId(); let parentClass = isPC ? ".post-reply-list" : ".hp-m-post-page"; $(document).ready(function () { $(parentClass).each(function (i, e) { removeImg(e, blockIds); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { console.log(mutation.type) if (mutation.type === 'childList') { removeImg(e, blockIds); } }); }); var config = { childList: true, attributes: true,subtree: true}; observer.observe(e, config); }) }); } let smallAll = GM_getValue(GM_KEY_SMALL_ALL, false); if (smallAll) { $(document).ready(function () { smallAllImage(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { console.log(mutation.type) if (mutation.type === 'childList') { smallAllImage() } }); }); var config = { childList: true, attributes: true,subtree: true}; observer.observe(document, config); }); } })(); function registerMenu() { let blockAll = GM_getValue(GM_KEY_BLOCK_ALL, false); if (blockAll) { menus[3].name = "✔️已屏蔽回帖中所有图片" } let smallAll = GM_getValue(GM_KEY_SMALL_ALL, false); if (smallAll) { menus[2].name = "✔️已缩小回帖中所有图片" } for (let m of menus) { m.id = GM_registerMenuCommand(m.name, m.func, ""); } } function checkImgSuffix(url) { let urlLower = url.toLowerCase(); let suffixs = [".jpg", ".png", ".jpeg", ".gif", ".webp"]; // console.log(urlLower); for (let s of suffixs) { if (urlLower.includes(s)) { return true; } } return false; } function initShowImage() { let showImage = GM_getValue(GM_KEY_SHOW_IMAGE, []); if (showImage.length === 0) { settingRemote() } } 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 (checkImgSuffix(split)) { let split2 = split.split("."); id = split2[0]; break; } } } return [id, image]; } //e是.image-wrapper function removeImg(e, blockIds) { 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 blockIds) { if (src.includes(black)) { $(e2).parents(imgParent).first().remove(); break; } } }); } function selectCheckbox(e) { let checked = e.checked; let id = $(e).attr("id"); let checkIds = getBlockId(); if (checked) { checkIds.add(id); } else { checkIds.delete(id); } setBlockId(checkIds) } function settingSwitch() { // 初始化打开开关 addUI(); let checkIds = getBlockId(); 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" + " |