HideImage

隐藏所有图片,直到你想看到她

  1. // ==UserScript==
  2. // @name HideImage
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.5
  5. // @description 隐藏所有图片,直到你想看到她
  6. // @author idealy
  7. // @match *://linux.do/*
  8. // @match *://hostloc.com/*
  9. // @match *://app.follow.is/*
  10. // @match *://mp.weixin.qq.com/*
  11. // @match *://baijiahao.baidu.com/*
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // 默认配置项:最小宽度和高度
  19. const defaultMinWidth = 100;
  20. const defaultMinHeight = 100;
  21.  
  22. // 针对不同网站的配置
  23. const siteConfigs = {
  24. 'linux.do': {
  25. excludeClasses: ['mfp-img']
  26. },
  27. 'hostloc.com': {
  28. minWidth: 200,
  29. minHeight: 200
  30. }
  31. };
  32.  
  33. function getSiteConfig() {
  34. const domain = window.location.hostname;
  35. return siteConfigs[domain] || {};
  36. }
  37.  
  38. function shouldExcludeImage(img) {
  39. const config = getSiteConfig();
  40. if (config.excludeClasses) {
  41. return config.excludeClasses.some(className => img.classList.contains(className));
  42. }
  43. return false;
  44. }
  45.  
  46. function replaceImagesWithText(img) {
  47. const config = getSiteConfig();
  48. const minWidth = config.minWidth || defaultMinWidth;
  49. const minHeight = config.minHeight || defaultMinHeight;
  50.  
  51. if (img.style.display !== 'none' && img.width >= minWidth && img.height >= minHeight && !shouldExcludeImage(img)) {
  52. const width = img.width;
  53. const height = img.height;
  54. const text = document.createElement('span');
  55. text.textContent = `图片 ${width}*${height}`;
  56. text.style.cursor = 'pointer';
  57. text.addEventListener('click', () => {
  58. img.style.display = '';
  59. text.style.display = 'none';
  60. img.addEventListener('click', () => {
  61. img.style.display = 'none';
  62. text.style.display = '';
  63. }, { once: true });
  64. });
  65. img.parentNode.insertBefore(text, img);
  66. img.style.display = 'none';
  67. console.log('已隐藏图片:', img.src);
  68. }
  69. }
  70.  
  71. function handleImage(img) {
  72. if (img.dataset.processed) return;
  73. img.dataset.processed = 'true';
  74. console.log('检测到图片:', img.src);
  75. if (img.complete) {
  76. replaceImagesWithText(img);
  77. } else {
  78. img.addEventListener('load', () => replaceImagesWithText(img));
  79. img.addEventListener('error', () => replaceImagesWithText(img));
  80. }
  81. }
  82.  
  83. function handleExistingImages() {
  84. const images = document.querySelectorAll('img');
  85. images.forEach(handleImage);
  86. }
  87.  
  88. function observeDOMChanges() {
  89. const observer = new MutationObserver((mutations) => {
  90. mutations.forEach(mutation => {
  91. if (mutation.type === 'childList') {
  92. mutation.addedNodes.forEach(node => {
  93. if (node.nodeType === Node.ELEMENT_NODE) {
  94. if (node.tagName === 'IMG') {
  95. handleImage(node);
  96. } else {
  97. const images = node.querySelectorAll('img');
  98. images.forEach(handleImage);
  99. }
  100. }
  101. });
  102. } else if (mutation.type === 'attributes' && mutation.target.tagName === 'IMG') {
  103. handleImage(mutation.target);
  104. }
  105. });
  106. });
  107. observer.observe(document.body, {
  108. childList: true,
  109. subtree: true,
  110. attributes: true,
  111. attributeFilter: ['src']
  112. });
  113. }
  114.  
  115. window.onload = () => {
  116. handleExistingImages();
  117. observeDOMChanges();
  118. };
  119. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址