无图模式

点击脚本菜单关闭/开启页面图片

  1. // ==UserScript==
  2. // @name 无图模式
  3. // @namespace http://tampermonkey.net/
  4. // @license MIT
  5. // @version 0.9
  6. // @icon https://qwn3213.com/icon/tupian.png
  7. // @description 点击脚本菜单关闭/开启页面图片
  8. // @author Q伟N
  9. // @match *://*/*
  10. // @require http://code.jquery.com/jquery-latest.js
  11. // @grant GM_registerMenuCommand
  12. // @grant GM_unregisterMenuCommand
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19. var host = window.location.hostname;
  20. var imgShow = GM_getValue(host);
  21. console.log("imgShow="+imgShow);
  22. if (imgShow === false) {
  23. setTimeout(function() {
  24. hide_img();
  25. GM_registerMenuCommand('暂时显示', function () {$('img').show();$('.hidden-image-notice').remove();}, 't');
  26. }, 380);
  27. } else {
  28. imgShow = true;
  29. }
  30.  
  31. var observer = new MutationObserver(function(mutations) {
  32. mutations.forEach(function(mutation) {
  33. if (mutation.addedNodes) {
  34. mutation.addedNodes.forEach(function(node) {
  35. var nextElement = node.nextElementSibling;
  36. if ((node.nodeType === 1 && (node.nodeName === 'IMG' || node.getElementsByTagName('img').length > 0)) && imgShow === false && nextElement && nextElement.classList.contains('hidden-image-notice')){
  37. hide_img();
  38. }
  39. });
  40. }
  41. });
  42. });
  43.  
  44. observer.observe(document.body, {
  45. childList: true,
  46. subtree: true
  47. });
  48.  
  49. function menu_change() {
  50. imgShow = !imgShow;
  51. if (imgShow) {
  52. $('img').show();
  53. $('.hidden-image-notice').remove();
  54. } else {
  55. hide_img();
  56. }
  57. GM_setValue(host, imgShow);
  58. GM_unregisterMenuCommand(menuId);
  59. menuId = GM_registerMenuCommand((imgShow ? '✅': '❌') + '图', menu_change, 'h');
  60. }
  61.  
  62.  
  63. function hide_img() {
  64. if (imgShow) {
  65. return;
  66. }
  67. $('img').each(function() {
  68. var $this = $(this);
  69. var imgSrc = $this.attr('src');
  70. var displayedWidth = $this.width();
  71. var displayedHeight = $this.height();
  72. console.log("displayedWidth:"+displayedWidth+",displayedHeight:"+displayedHeight+"------imgSrc="+imgSrc);
  73. if(displayedWidth>100 || displayedHeight>100){
  74. $this.hide();
  75. if (!$this.next().is('.hidden-image-notice')) {
  76. $this.after('<div class="hidden-image-notice"><a href="' + imgSrc + '" target="_blank">『图』</a></div>');
  77. }
  78. }
  79. });
  80. }
  81. var menuId = GM_registerMenuCommand((imgShow ? '✅': '❌') + '图', menu_change, 'h');
  82. })();

QingJ © 2025

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