IThome Fix

去除「IT之家」博客版信息流广告

  1. // ==UserScript==
  2. // @name IThome Fix
  3. // @namespace http://your-namespace.com
  4. // @version 3.3
  5. // @description 去除「IT之家」博客版信息流广告
  6. // @author https://blog.tongmingzhi.com
  7. // @match https://www.ithome.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Function to set rounded images with proportional height and a border
  15. function setRoundedImages() {
  16. var images = document.querySelectorAll('img');
  17. images.forEach(function(image) {
  18. if (image.width >= 30) {
  19. image.parentElement.style.border = 'none';
  20. image.style.borderRadius = '12px';
  21. image.style.border = '2px solid #CCC';
  22.  
  23. if (image.height > 150) {
  24. image.style.borderRadius = '12px';
  25. image.style.border = '2px solid #CCC';
  26. image.style.display = 'inline';
  27. image.style.maxWidth = '400px';
  28. image.style.height = 'auto';
  29. image.style.objectFit = 'cover';
  30. image.style.overflow = 'hidden';
  31. }
  32. }
  33. });
  34. }
  35.  
  36. // Function to set rounded corners for comments
  37. function setRounded() {
  38. var roundeds = document.querySelectorAll(
  39. '.comm_list ul.list li.entry ul.reply, ' +
  40. '.content .post_content blockquote, ' +
  41. '.add_comm input#btnComment' +
  42. '.card, span.card'
  43. );
  44. roundeds.forEach(function (rounded) {
  45. rounded.style.borderRadius = '12px';
  46. });
  47.  
  48. var addCommElements = document.querySelectorAll('.add_comm');
  49. addCommElements.forEach(function (addCommElement) {
  50. addCommElement.style.borderRadius = '0px 0px 12px 12px';
  51. });
  52.  
  53. var Cards = document.querySelectorAll('.card, span.card');
  54. Cards.forEach(function (card) {
  55. card.style.transform = 'scale(0.8)';
  56. });
  57.  
  58. var Videos = document.querySelectorAll('.ithome_super_player');
  59. Videos.forEach(function (Video) {
  60. Video.style.border = '2px solid #CCC !important';
  61. Video.style.borderRadius = '12px';
  62. Video.style.marginLeft = 'auto';
  63. Video.style.marginRight = 'auto';
  64. Video.style.width = '400px';
  65. Video.style.height = 'atuo';
  66. });
  67.  
  68. }
  69.  
  70. // Function to remove ads
  71. function removeAds() {
  72. document.querySelectorAll(
  73. 'div.bb.clearfix > div.fl > ul.bl > li'
  74. ).forEach(function(element) {
  75. if (element.querySelector('div.c > div.m:empty')) {
  76. element.remove();
  77. }
  78. });
  79. }
  80.  
  81. // Function to observe DOM changes
  82. function observeDOM() {
  83. var targetNode = document.body;
  84. var config = { childList: true, subtree: true };
  85.  
  86. var callback = function(mutationsList, observer) {
  87. for (var mutation of mutationsList) {
  88. if (mutation.type === 'childList') {
  89. setRoundedImages();
  90. setRounded();
  91. removeAds();
  92. }
  93. }
  94. };
  95.  
  96. var observer = new MutationObserver(callback);
  97. observer.observe(targetNode, config);
  98.  
  99. return observer;
  100. }
  101.  
  102. function checkDOMChanges() {
  103. var observer = observeDOM();
  104.  
  105. var interval = setInterval(function() {
  106. setRoundedImages();
  107. setRounded();
  108. removeAds();
  109. }, 20);
  110.  
  111. return interval;
  112. }
  113.  
  114. window.addEventListener('load', function() {
  115. setRoundedImages();
  116. setRounded();
  117. removeAds();
  118.  
  119. var intervalID = checkDOMChanges();
  120.  
  121. setTimeout(function() {
  122. clearInterval(intervalID);
  123. }, 60000);
  124. });
  125. })();