您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
隐藏所有图片,直到你想看到她
当前为
- // ==UserScript==
- // @name HideImage
- // @namespace http://tampermonkey.net/
- // @version 1.0.0
- // @description 隐藏所有图片,直到你想看到她
- // @author idealy
- // @match *://*/*
- // @grant none
- // @license MIT
- // ==/UserScript==
- (function() {
- 'use strict';
- // 配置项:最小宽度和高度
- const minWidth = 100;
- const minHeight = 100;
- // 字典管理特定域名下的特定类名
- const excludeClasses = {
- 'linux.do': ['mfp-img'],
- 'recaptcha.net':['rc-imageselect-checkbox']
- };
- function shouldExcludeImage(img) {
- const domain = window.location.hostname;
- if (excludeClasses[domain]) {
- return excludeClasses[domain].some(className => img.classList.contains(className));
- }
- return false;
- }
- function replaceImagesWithText(img) {
- if (img.style.display !== 'none' && img.width >= minWidth && img.height >= minHeight && !shouldExcludeImage(img)) {
- const width = img.width;
- const height = img.height;
- const text = document.createElement('span');
- text.textContent = `图片 ${width}*${height}`;
- text.style.cursor = 'pointer';
- text.addEventListener('click', () => {
- img.style.display = '';
- text.style.display = 'none';
- img.addEventListener('click', () => {
- img.style.display = 'none';
- text.style.display = '';
- }, { once: true });
- });
- img.parentNode.insertBefore(text, img);
- img.style.display = 'none';
- console.log('已隐藏图片:', img.src);
- }
- }
- function handleImage(img) {
- if (img.dataset.processed) return;
- img.dataset.processed = 'true';
- console.log('检测到图片:', img.src);
- if (img.complete) {
- replaceImagesWithText(img);
- } else {
- img.addEventListener('load', () => replaceImagesWithText(img));
- img.addEventListener('error', () => replaceImagesWithText(img));
- }
- }
- function handleExistingImages() {
- const images = document.querySelectorAll('img');
- images.forEach(handleImage);
- }
- function observeDOMChanges() {
- const observer = new MutationObserver((mutations) => {
- mutations.forEach(mutation => {
- if (mutation.type === 'childList') {
- mutation.addedNodes.forEach(node => {
- if (node.nodeType === Node.ELEMENT_NODE) {
- if (node.tagName === 'IMG') {
- handleImage(node);
- } else {
- const images = node.querySelectorAll('img');
- images.forEach(handleImage);
- }
- }
- });
- } else if (mutation.type === 'attributes' && mutation.target.tagName === 'IMG') {
- handleImage(mutation.target);
- }
- });
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true,
- attributes: true,
- attributeFilter: ['src']
- });
- }
- window.onload = () => {
- handleExistingImages();
- observeDOMChanges();
- };
- })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址