remove-adds

remove adds

  1. // ==UserScript==
  2. // @name remove-adds
  3. // @name:CN-zh_cn 移除广告
  4. // @version 0.14
  5. // @description remove adds
  6. // @author gaojr
  7. // @namespace https://github.com/gaojr/scripts-styles
  8. // @license MIT
  9. // @match https://*/*
  10. // @require https://greasyfork.org/scripts/393085-commonsutil/code/CommonsUtil.js
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. const wlh = window.location.href;
  15.  
  16. // 目标[选择器|元素]
  17. const targets = [];
  18.  
  19. /**
  20. * 移除目标
  21. */
  22. const removeTargetAsSelector = () => {
  23. // 用英文逗号拼接选择器
  24. let selector = targets.join();
  25. if (!selector) {
  26. return;
  27. }
  28. removeAll(selector);
  29. // 清空列表
  30. targets.length = 0;
  31. };
  32.  
  33. /**
  34. * 移除目标
  35. */
  36. const removeTargetAsElement = () => {
  37. targets.forEach((ele) => {
  38. removeRecursively(ele);
  39. });
  40. // 清空列表
  41. targets.length = 0;
  42. };
  43.  
  44. ////////// 分割线
  45.  
  46. /**
  47. * 清楚iframe
  48. */
  49. const cleanIframe = () => {
  50. const baidu = /https:\/\/pos\.baidu\.com\//;
  51. const google = /https:\/\/googleads/;
  52.  
  53. _$$('iframe').forEach((ele) => {
  54. let src = ele.src;
  55. if (baidu.test(src) || google.test(src)) {
  56. targets.push(ele);
  57. }
  58. });
  59. };
  60.  
  61. /**
  62. * 通用
  63. */
  64. const deal = (list) => {
  65. list.forEach((e) => {
  66. _$$(e).forEach((ele) => {
  67. if (!ele.textContent.trim()) {
  68. targets.push(ele);
  69. }
  70. });
  71. });
  72. removeTargetAsElement();
  73. }
  74.  
  75. /**
  76. * 通用-广告
  77. */
  78. const dealCommons = () => {
  79. _$$('[data-google-query-id]').forEach((ele) => {
  80. targets.push(ele);
  81. });
  82. _$$('[aria-label]').forEach((ele) => {
  83. let label = ele.getAttribute('aria-label');
  84. if (/baidu-ad/.test(label)) {
  85. targets.push(ele);
  86. }
  87. });
  88. };
  89.  
  90. /**
  91. * 通用-脚本
  92. */
  93. const dealScripts = () => {
  94. // 干掉 body 里的脚本
  95. targets.push('body script');
  96. removeTargetAsSelector();
  97. };
  98.  
  99. ////////// 分割线
  100.  
  101. /**
  102. * CSDN
  103. */
  104. const dealCsdn = () => {
  105. // 文章页面
  106. const article = /https:\/\/.*\.csdn\.net\/.*\/article\/details\/.*/;
  107.  
  108. if (article.test(wlh)) {
  109. clickIt('.btn-readmore');
  110. }
  111. };
  112.  
  113. /**
  114. * 异次元 iplaysoft.com
  115. */
  116. const dealIplaysoft = () => {
  117. // 全局
  118. dealScripts();
  119.  
  120. // 文章页面
  121. const article = /https:\/\/www\.iplaysoft\.com\/.+/;
  122.  
  123. if (article.test(wlh)) {
  124. // 删掉有 style、无 id、无 class、无文字的 div
  125. _$$('div[style]:not([id]):not([class])').forEach((ele) => {
  126. if (!ele.textContent.trim()) {
  127. ele.remove();
  128. }
  129. });
  130. }
  131. };
  132.  
  133. ////////// 分割线
  134.  
  135. (function () {
  136. let func = () => {
  137. cleanIframe();
  138. dealCommons();
  139. removeTargetAsElement();
  140.  
  141. const isCsdn = /https?:\/\/.*\.csdn\.net((\/.*)|(\/?))/;
  142. const isIplaysoft = /https?:\/\/www\.iplaysoft\.com((\/.*)|(\/?))/;
  143. const isWenku8 = /https?:\/\/www\.wenku8\.net\/novel((\/.*)|(\/?))/;
  144.  
  145. if (isCsdn.test(wlh)) {
  146. dealCsdn();
  147. } else if (isIplaysoft.test(wlh)) {
  148. dealIplaysoft();
  149. } else if (isWenku8.test(wlh)) {
  150. deal(['div#adv900']);
  151. }
  152. removeTargetAsSelector();
  153. };
  154. addToFuncMap('resmove-add', func);
  155. })();