RemoveAdds

remove adds

当前为 2019-12-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @author gaojr
  3. // @namespace https://github.com/gaojr/tampermonkey-scripts
  4. // @name:CN-zh_cn 移除广告
  5. // @name RemoveAdds
  6. // @version 0.4
  7. // @description remove adds
  8. // @license MIT
  9. // @match https://blog.csdn.net/*
  10. // @match https://*.baidu.com/*
  11. // @match https://www.iplaysoft.com/*
  12. // @match https://www.jianshu.com/*
  13. // @require https://greasyfork.org/scripts/393085-commonsutil/code/CommonsUtil.js?version=754478
  14. // @require https://greasyfork.org/scripts/393202-cssutil/code/CssUtil.js?version=754549
  15. // @grant none
  16. // @run-at document-end
  17. // ==/UserScript==
  18.  
  19. const wlh = window.location.href;
  20.  
  21. // 目标[选择器]
  22. const targets = [];
  23.  
  24. /**
  25. * 移除目标
  26. */
  27. const removeTarget = function () {
  28. // 用英文逗号拼接选择器
  29. let selector = targets.join();
  30. if (!selector) {
  31. return;
  32. }
  33. removeAll(selector);
  34. // 清空列表
  35. targets.length = 0;
  36. };
  37.  
  38. ////////// 分割线
  39.  
  40. /**
  41. * 通用-广告
  42. */
  43. const dealCommons = function () {
  44. targets.push('.adsbygoogle');
  45. removeTarget();
  46. };
  47. /**
  48. * 通用-脚本
  49. */
  50. const dealScripts = function () {
  51. targets.push('body script');
  52. removeTarget();
  53. };
  54.  
  55. ////////// 分割线
  56.  
  57. /**
  58. * 百度
  59. */
  60. const dealBaidu = function () {
  61. // 贴吧
  62. const tieba = /https:\/\/tieba\.baidu\.com\/.+/;
  63. // 贴吧-吧
  64. const tieba_bar = /https:\/\/tieba\.baidu\.com\/f\?.+/;
  65. // 贴吧-帖子
  66. const tieba_article = /https:\/\/tieba\.baidu\.com\/p\/.+/;
  67.  
  68.  
  69. if (tieba.test(wlh)) {
  70. // 广告悬浮框
  71. targets.push('body > div.clearfix');
  72. }
  73. if (tieba_bar.test(wlh)) {
  74. // 右边的会员、热议、广告
  75. targets.push('#pagelet_encourage-celebrity\\/pagelet\\/celebrity');
  76. targets.push('#pagelet_frs-aside\\/pagelet\\/hottopic');
  77. targets.push('#pagelet_frs-aside\\/pagelet\\/ad');
  78. targets.push('#branding_ads');
  79. // 列表中的广告
  80. targets.push('#thread_list > li.clearfix:not(.j_thread_list)');
  81. } else if (tieba_article.test(wlh)) {
  82. targets.push('#j_p_postlist > div.clearfix[ad-dom-img]');
  83. }
  84. };
  85.  
  86. /**
  87. * CSDN
  88. */
  89. const dealCsdn = function () {
  90. // 文章页面
  91. const article = /https:\/\/.*\.csdn\.net\/.*\/article\/details\/.*/;
  92.  
  93. if (article.test(wlh)) {
  94. targets.push('#dmp_ad_58');
  95. targets.push('#mainBox > aside');
  96. targets.push('.tool-box.vertical');
  97. targets.push('.recommend-box');
  98. targets.push('body>div:last-child');
  99. clickIt('#mainBox > main > div.hide-article-box.hide-article-pos.text-center > a');
  100. clearCenter('#mainBox > main');
  101. }
  102. };
  103.  
  104. /**
  105. * 异次元 iplaysoft.com
  106. */
  107. const dealIplaysoft = function () {
  108. // 全局
  109. dealScripts();
  110. targets.push('iframe');
  111. targets.push('.crumb_ad');
  112. targets.push('div#sidebar');
  113.  
  114. // 首页
  115. const home = /https:\/\/www\.iplaysoft\.com\/?$/;
  116. // 文章页面
  117. const article = /https:\/\/www\.iplaysoft\.com\/.+/;
  118.  
  119. if (home.test(wlh)) {
  120. // 删除广告
  121. targets.push('#show_post_side');
  122. targets.push('#section_event');
  123. targets.push('#section_hot');
  124. // 样式调整
  125. clearCenter('#show_post_entry,#postlist');
  126. } else if (article.test(wlh)) {
  127. // 删除广告
  128. targets.push('.post .entry-content + div');
  129. targets.push('.post > div.entry-meta.clear > ul.same-cat-post + div');
  130. // 删除回复
  131. targets.push('div#respond');
  132.  
  133. // 删掉有 style、无 id、无 class、无文字的 div
  134. document.querySelectorAll('div[style]:not([id]):not([class])').forEach(function (ele) {
  135. if (!ele.textContent.trim()) {
  136. ele.remove();
  137. }
  138. });
  139. // 样式调整
  140. floatNone('#container #content');
  141. marginCenter('#container #content, #share_toolbar,.entry-banner,#respond');
  142. }
  143. };
  144.  
  145. /**
  146. * 简书
  147. */
  148. const dealJianshu = function () {
  149. // 文章页面
  150. const article = /https:\/\/www\.jianshu\.com\/p\/.+/;
  151.  
  152. if (article.test(wlh)) {
  153. targets.push('#__next ._3Pnjry,#__next > div._21bLU4._3kbg6I > div > aside,#__next > div._21bLU4._3kbg6I > div > div._gp-ck');
  154. }
  155. };
  156.  
  157. ////////// 分割线
  158.  
  159. (function () {
  160. 'use strict';
  161.  
  162. window.onload = function () {
  163. console.log('remove-adds start!');
  164. dealCommons();
  165.  
  166. const isBaidu = /https?:\/\/.*\.baidu\.com((\/.*)|(\/?))/;
  167. const isCsdn = /https?:\/\/.*\.csdn\.net((\/.*)|(\/?))/;
  168. const isIplaysoft = /https?:\/\/www\.iplaysoft\.com((\/.*)|(\/?))/;
  169. const isJianshu = /https?:\/\/www\.jianshu\.com((\/.*)|(\/?))/;
  170.  
  171. if (isBaidu.test(wlh)) {
  172. dealBaidu();
  173. } else if (isCsdn.test(wlh)) {
  174. dealCsdn();
  175. } else if (isIplaysoft.test(wlh)) {
  176. dealIplaysoft();
  177. } else if (isJianshu.test(wlh)) {
  178. dealJianshu();
  179. }
  180. removeTarget();
  181. console.log('remove-adds end!');
  182. }
  183.  
  184. })();