CSDN净化

filter/format csdn css

  1. // ==UserScript==
  2. // @name CSDN净化
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.0
  5. // @description filter/format csdn css
  6. // @author 细粒丁
  7. // @match *://*.csdn.net/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. const config = {
  17. blog_container_aside: true, // 左边侧边栏
  18. left: {
  19. asideProfile: true, // 用户信息简介(左边)
  20. asideSearchArticle: true, // 搜索博主文章(左边)
  21. asideHotArticle: true, // 热门文章(左边)
  22. asideCategory: true, // 分类专栏(左边)
  23. asideNewComments: true, // 最新评论(左边)
  24. asideNewNps: true, // 推荐意愿(左边)
  25. asideArchive: true, // 最新文章(左边)
  26. },
  27. rightAside: false, // 右边侧边栏
  28. right: {
  29. groupfile: true, // 目录(右边)
  30. programmer1Box: true, // 广告(右边)
  31. "aside-box kind_person d-flex flex-column": true, // 分类专栏(右边)
  32. },
  33. recommendDownloadFilter: true, // 过滤末尾推荐文章中的资源下载
  34. }
  35.  
  36. const list = {
  37. recommendNps: true, // 相关推荐调查(底部)
  38. "blog-footer-bottom": true, // 底部声明(底部)
  39. "recommend-box": false, // 文章末尾的推荐文章(底部)
  40. "sidetool-writeguide-box": true // 创作话题
  41. }
  42.  
  43.  
  44. function format(key) {
  45. let id = "#" + key
  46. let cls = "." + key.replace(/\s/g, ".")
  47. return `${id},${cls}`
  48. }
  49.  
  50. function del(obj) {
  51. let target = true
  52. for (const key in obj) {
  53. const element = obj[key];
  54. if (element) {
  55. let arr = document.querySelectorAll(format(key))
  56. for (let i = 0; i < arr.length; i++) {
  57. const item = arr[i];
  58. item.remove()
  59. }
  60. } else {
  61. target = false
  62. }
  63. }
  64. return target
  65. }
  66.  
  67. del(list)
  68.  
  69. if ((config.blog_container_aside && document.querySelector(".blog_container_aside").remove()) || del(config.left)) {
  70. let main = document.querySelector("main")
  71. main.style.width = "100%"
  72. main.style.float = "none"
  73. }
  74.  
  75. if (config.rightAside || del(config.right)) {
  76. document.querySelector("#rightAside").remove()
  77. }
  78.  
  79. if (config.recommendDownloadFilter & !list["recommend-box"]) {
  80. const linklist = document.querySelectorAll(".recommend-item-box")
  81. for (let i = 0; i < linklist.length; i++) {
  82. const element = linklist[i];
  83. const url = element.getAttribute("data-url")
  84. url && url.includes("download.csdn.net") && element.remove()
  85. }
  86. }
  87.  
  88.  
  89. })();