知识星球样式优化(自用)

修改知识星球样式(自用)

  1. // ==UserScript==
  2. // @name 知识星球样式优化(自用)
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.2
  5. // @description 修改知识星球样式(自用)
  6. // @match https://wx.zsxq.com/*
  7. // @grant GM_addStyle
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. // 添加自定义样式
  15. GM_addStyle(`
  16. .group-list-container {
  17. transition: transform 0.2s ease-out;
  18. background: #fff;
  19. z-index: 10;
  20. }
  21. #toggle-sidebar {
  22. height: 20px;
  23. font-size: 12px;
  24. margin-left: 10px;
  25. padding: 0px 6px;
  26. border-radius: 4px;
  27. cursor: pointer;
  28. color: rgb(80, 234, 203);
  29. background-color: rgba(52, 146, 112, 0.05);
  30. border: 1px solid rgba(65,183,140,.2);
  31. }
  32. #toggle-sidebar:hover {
  33. background-color: #e0e0e0;
  34. }
  35. `);
  36.  
  37. function addRedBorder() {
  38. const listItems = document.querySelectorAll('.ng-star-inserted');
  39. listItems.forEach((item) => {
  40. const headerContainer = item.querySelector('.header-container');
  41. if (headerContainer) {
  42. const topicFlag = headerContainer.querySelector('.topic-flag');
  43. if (topicFlag) {
  44. const digestElement = topicFlag.querySelector('.digest');
  45. if (digestElement) {
  46. const topicContainer = item.querySelector('.topic-container');
  47. if (topicContainer) {
  48. topicContainer.style.border = '1px solid rgb(80, 234, 203)';
  49. topicContainer.style.backgroundColor = 'rgba(80, 234, 203, 0.1)';
  50. }
  51. }
  52. }
  53. }
  54. });
  55. }
  56.  
  57. function setupSidebarToggle() {
  58. const sidebar = document.querySelector('.group-list-container');
  59. const logoContainer = document.querySelector('.logo-container');
  60. if (!sidebar || !logoContainer) return;
  61.  
  62. const toggleButton = document.createElement('button');
  63. toggleButton.id = 'toggle-sidebar';
  64. toggleButton.textContent = '切换目录';
  65. logoContainer.appendChild(toggleButton);
  66.  
  67. // 获取视口宽度
  68. const clientWidth = document.documentElement.clientWidth;
  69. const transX = clientWidth - 1526 / 2;
  70.  
  71. // 默认隐藏侧边栏
  72. sidebar.classList.add('hide');
  73. // 设置hide样式
  74. if (sidebar.classList.contains('hide')) {
  75. sidebar.style.transform = 'translateX(calc(-100% - ' + transX + 'px))';
  76. } else {
  77. sidebar.style.transform = 'translateX(0)';
  78. }
  79.  
  80. toggleButton.addEventListener('click', () => {
  81. sidebar.classList.toggle('hide');
  82.  
  83. if (sidebar.classList.contains('hide')) {
  84. sidebar.style.transform = 'translateX(calc(-100% - ' + transX + 'px))';
  85. } else {
  86. sidebar.style.transform = 'translateX(0)';
  87. }
  88. });
  89. }
  90.  
  91. function hideElements() {
  92. // 头部
  93. const headerContainer = document.querySelector('.header-container');
  94.  
  95. if (headerContainer) {
  96. const redirect = headerContainer.querySelector('.redirect');
  97. const userAvatar = headerContainer.querySelector('.user-avatar');
  98.  
  99. if (redirect) {
  100. redirect.style.display = 'none';
  101. }
  102. if (userAvatar) {
  103. userAvatar.style.display = 'none';
  104. }
  105. }
  106.  
  107. const leftLogo = document.querySelector('.logo-container .left');
  108. const noteLogo = document.querySelector('.logo-container .note');
  109. if (leftLogo) {
  110. leftLogo.style.display = 'none';
  111. }
  112. if (noteLogo) {
  113. noteLogo.style.display = 'none';
  114. }
  115.  
  116. // .topic-flow-container
  117. const topicFlowContainer = document.querySelector('.topic-flow-container');
  118. if (topicFlowContainer) {
  119. topicFlowContainer.style.setProperty('width', '100%', 'important');
  120. topicFlowContainer.style.setProperty('padding-left', '100px', 'important');
  121. topicFlowContainer.style.setProperty('padding-right', '100px', 'important');
  122. }
  123.  
  124. // 主体上部分
  125. const topicContainer = document.querySelector('.topic-container');
  126. if (topicContainer) {
  127. const ngStarInserted = topicContainer.querySelector('.ng-star-inserted');
  128. if (ngStarInserted) {
  129. ngStarInserted.style.display = 'none';
  130. }
  131. }
  132.  
  133. // 主体中部分
  134. const mainContentContainer = document.querySelector('.main-content-container');
  135. if (mainContentContainer) {
  136. mainContentContainer.style.setProperty('margin-left', '10%', 'important');
  137. mainContentContainer.style.setProperty('margin-right', '10%', 'important');
  138. }
  139.  
  140. // 右侧边栏
  141. const groupPreviewContainer = document.querySelector('.group-preview-container');
  142.  
  143. if (groupPreviewContainer) {
  144. groupPreviewContainer.style.display = 'none';
  145. // const groupInfoContainer = groupPreviewContainer.querySelector('.group-info-container');
  146. // const askContainer = groupPreviewContainer.querySelector('.ask-container');
  147. // const groupContent = groupPreviewContainer.querySelector('.group-content');
  148.  
  149. // if (groupInfoContainer) {
  150. // groupInfoContainer.style.display = 'none';
  151. // }
  152.  
  153. // if (askContainer) {
  154. // askContainer.style.display = 'none';
  155. // }
  156.  
  157. // if (groupContent) {
  158. // groupContent.style.display = 'none';
  159. // }
  160. }
  161. }
  162.  
  163. function init() {
  164. console.log('init------------');
  165. hideElements();
  166. addRedBorder();
  167. setupSidebarToggle();
  168. }
  169.  
  170. // 在页面加载完成后执行
  171. window.addEventListener('load', init);
  172.  
  173. // 为了处理动态加载的内容,每隔一段时间检查一次
  174. setInterval(addRedBorder, 5000);
  175. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址