CSDN博客专用

CSDN博客网站专用 自动展开+去除页面广告+长期更新

  1. // ==UserScript==
  2. // @name CSDN博客专用
  3. // @namespace zhaoxiufei@gmail.com
  4. // @version 1.3.3
  5. // @description CSDN博客网站专用 自动展开+去除页面广告+长期更新
  6. // @author zhaoxiufei
  7. // @match *://blog.csdn.net/*
  8. // @require http://code.jquery.com/jquery-3.3.1.slim.min.js
  9. // @run-at document-end
  10. // ==/UserScript==
  11. (function () {
  12. 'use strict';
  13. let isDebug = true;
  14. let log = isDebug ? console.log.bind(console) : function () {
  15. };
  16.  
  17. let i = 0;
  18. //自动展开
  19. let clean = window.setInterval(cleanAd, 500);
  20.  
  21. function displayOne(name, selector) {
  22. let ad = document.querySelector(selector);
  23. if (ad) {
  24. ad.style.display = "none";
  25. log(name + "已执行");
  26. } else {
  27. log(name + "未执行");
  28. }
  29. }
  30. function displayAll(name, selector) {
  31. let ad = document.querySelectorAll(selector);
  32. if (ad) {
  33. for (let i = 0; i < ad.length; i++) {
  34. ad[i].style.display = "none";
  35. }
  36. log(name + "已执行");
  37. } else {
  38. log(name + "未执行");
  39. }
  40. }
  41. function displayAll2(name, selector) {
  42. let ad = document.querySelectorAll(selector);
  43. if (ad) {
  44. for (let i = 0; i < ad.length; i++) {
  45. if(ad[i].getAttribute("data-track-click").indexOf("baidu.com")!=-1){
  46. ad[i].style.display = "none";
  47. }
  48. }
  49. log(name + "已执行");
  50. } else {
  51. log(name + "未执行");
  52. }
  53. }
  54. //
  55. function removeOne(name, selector) {
  56. let ad = document.querySelector(selector);
  57. if (ad) {
  58. $(selector).remove();
  59. log(name + "已执行");
  60. }
  61. }
  62. function removeAttr(name, selector,attr) {
  63. let ad = document.querySelector(selector);
  64. if (ad) {
  65. $(selector).removeAttr(attr);;
  66. log(name + "已执行");
  67. }
  68. }
  69. function cleanAd() {
  70. if (i >= 2) {
  71. clearInterval(clean)
  72. }
  73. log("执行");
  74. //自动展开
  75. removeAttr("ad000","#article_content","style");
  76. removeOne("ad00","#mainBox > main > div.blog-content-box > article > div.hide-article-box.text-center");
  77. displayAll2("xxoo","#mainBox > main > div.recommend-box > div.recommend-item-box.recommend-box-ident.type_blog")
  78. removeOne("ad0","#mainBox > div > ul");
  79. displayOne("ad1", "#mainBox > main > div.recommend-box > div.recommend-item-box.blog-expert-recommend-box");
  80. displayOne("ad2", "#mainBox > aside > div.csdn-tracking-statistics.mb8.box-shadow");
  81. //displayOne("ad3", "#mainBox > main > div.recommend-box > div.p4courset3_target._4paradigm_box.recommend-item-box.clearfix");
  82. displayAll("ad4", "[id^='dmp_ad_']");
  83. displayOne("ad5", "#mainBox > main > div.recommend-box > div.recommend-item-box.type_hot_word");
  84. displayOne("ad6", "#mainBox > main > div.recommend-box > div.recommend-item-box.recommend-ad-box");
  85. displayOne("ad7", "body > div.pulllog-box");
  86. displayAll("ad8", "#mainBox > main > div.recommend-box > div.recommend-item-box.recommend-ad-box");
  87. displayOne("ad9", "body > div.fourth_column");
  88. displayOne("ad10", "#asideFooter");
  89. i++;
  90. }
  91. })();