RemoveAdds

remove adds

当前为 2019-11-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @author gaojr
  3. // @namespace https://github.com/gaojr/tampermonkey-scripts
  4. // @name:CN-zh_cn 移除广告
  5. // @name RemoveAdds
  6. // @version 0.1
  7. // @description remove adds
  8. // @license MIT
  9. // @match https://blog.csdn.net/*
  10. // @match https://www.iplaysoft.com/*
  11. // @match https://www.jianshu.com/*
  12. // @grant GM_addStyle
  13. // @run-at document-end
  14. // ==/UserScript==
  15.  
  16. var href = window.location.href;
  17.  
  18. /**
  19. * CSDN
  20. */
  21. var dealCsdn = function () {
  22. // 文章页面
  23. var article = /https:\/\/.*\.csdn\.net\/.*\/article\/details\/.*/;
  24.  
  25. if (article.test(href)) {
  26. document.querySelector('#dmp_ad_58').remove();
  27. document.querySelector('#mainBox > aside').remove();
  28. document.querySelector('.tool-box.vertical').remove();
  29. document.querySelector('.recommend-box').remove();
  30. // document.querySelector('.csdn-side-toolbar').parentElement.remove();
  31. // document.querySelector('#mainBox > main > div.hide-article-box.hide-article-pos.text-center > a').click();
  32. GM_addStyle('#mainBox > main { float: none;margin-left: auto;margin-right: auto; }');
  33. }
  34. };
  35. /**
  36. * 异次元 iplaysoft.com
  37. */
  38. var dealIplaysoft = function () {
  39. // 全局
  40. document.querySelectorAll('body script').forEach(function (e) {
  41. e.remove();
  42. });
  43. document.querySelectorAll('iframe').forEach(function (e) {
  44. e.remove();
  45. });
  46. document.querySelectorAll('.adsbygoogle').forEach(function (e) {
  47. e.remove();
  48. });
  49. document.querySelectorAll('.crumb_ad').forEach(function (e) {
  50. e.remove();
  51. });
  52. document.querySelector('div#sidebar').remove();
  53.  
  54. // 首页
  55. var home = /https:\/\/www\.iplaysoft\.com\/?$/;
  56. // 文章页面
  57. var article = /https:\/\/www\.iplaysoft\.com\/.+/;
  58.  
  59. if (home.test(href)) {
  60. // 删除广告
  61. document.querySelector('#show_post_side').remove();
  62. document.querySelector('#section_event').remove();
  63. document.querySelector('#section_hot').remove();
  64. // 样式调整
  65. GM_addStyle('#show_post_entry,#postlist { float: none;margin-left: auto;margin-right: auto; }');
  66. } else if (article.test(href)) {
  67. // 删除广告
  68. document.querySelector('.post .entry-content').nextSibling.remove();
  69. document.querySelector('.post > div.entry-meta.clear > ul.same-cat-post').nextSibling.remove();
  70. // 删除回复
  71. document.querySelector('div#respond').remove();
  72.  
  73. // 删掉有 style、无 id、无 class、无文字的 div
  74. document.querySelectorAll('div').forEach(function (e) {
  75. if (!!e.getAttribute('style') && !e.getAttribute('id') && !e.getAttribute('class') && !e.textContent.trim()) {
  76. e.remove();
  77. }
  78. });
  79. // 样式调整
  80. GM_addStyle('#container #content { float: none;margin-left: auto;margin-right: auto; }');
  81. GM_addStyle('#share_toolbar,.entry-banner,#respond { margin-left: auto;margin-right: auto; }');
  82. }
  83. };
  84.  
  85. /**
  86. * 简书
  87. */
  88. var dealJianshu = function () {
  89. // 文章页面
  90. var article = /https:\/\/www\.jianshu\.com\/p\/.+/;
  91. if (article.test(href)) {
  92. GM_addStyle('#__next ._3Pnjry,#__next > div._21bLU4._3kbg6I > div > aside,#__next > div._21bLU4._3kbg6I > div > div._gp-ck { display: none; }');
  93. }
  94. };
  95.  
  96. (function () {
  97. 'use strict';
  98.  
  99. var isCsdn = /https:\/\/.*\.csdn\.net\/?.*/;
  100. var isIplaysoft = /https:\/\/www\.iplaysoft\.com\/?.*/;
  101. var isJianshu = /https:\/\/www\.jianshu\.com\/?.*/;
  102.  
  103. if (isCsdn.test(href)) {
  104. dealCsdn();
  105. } else if (isIplaysoft.test(href)) {
  106. dealIplaysoft();
  107. } else if (isJianshu.test(href)) {
  108. dealJianshu();
  109. }
  110.  
  111. })();