嗨皮漫画 - 收起、展开评论区

收起或展开嗨皮漫画评论区,并隐藏一些无关的元素。

  1. // ==UserScript==
  2. // @name 嗨皮漫畫 - 收起、展開評論區
  3. // @name:zh-TW 嗨皮漫畫 - 收起、展開評論區
  4. // @name:zh-CN 嗨皮漫画 - 收起、展开评论区
  5. // @name:ja ハッピーコミック - コメントエリアの折りたたみと展開
  6. // @name:en Happy Comics - Collapse and Expand Comments Section
  7. // @version 2.4
  8. // @description 收起或展開嗨皮漫畫評論區,並隱藏一些無關的元素。
  9. // @description:zh-TW 收起或展開嗨皮漫畫評論區,並隱藏一些無關的元素。
  10. // @description:zh-CN 收起或展开嗨皮漫画评论区,并隐藏一些无关的元素。
  11. // @description:ja Happy Comicsのコメントエリアを折りたたみ、展開し、関連のない要素を非表示にします。
  12. // @description:en Collapse or expand the comments section of Happy Comics, and hide some irrelevant elements.
  13. // @author Scott
  14. // @match *://m.happymh.com/reads/*
  15. // @match *://m.happymh.com/*
  16. // @grant unsafeWindow
  17. // @grant GM_addStyle
  18. // @license MIT
  19. // @namespace https://www.youtube.com/c/ScottDoha
  20. // ==/UserScript==
  21.  
  22.  
  23.  
  24. (function() {
  25. 'use strict';
  26.  
  27. var isCollapsed = true; // 默認為收起狀態
  28.  
  29. // 檢查按鈕狀態是否已從本地存儲中獲取
  30. if (localStorage.getItem('isCollapsed') !== null) {
  31. isCollapsed = localStorage.getItem('isCollapsed') === 'true';
  32. }
  33.  
  34. var observer = new MutationObserver(function(mutations) {
  35. mutations.forEach(function(mutation) {
  36. var addedNodes = mutation.addedNodes;
  37. for (var i = 0; i < addedNodes.length; i++) {
  38. var addedNode = addedNodes[i];
  39. if (addedNode.classList && addedNode.classList.contains('jss30')) {
  40. addToggleButton(addedNode);
  41. }
  42. }
  43.  
  44. hideUnrelatedElements();
  45. updateCommentSectionDisplay();
  46. });
  47. });
  48.  
  49. observer.observe(document.body, { childList: true, subtree: true });
  50.  
  51. function addToggleButton(article) {
  52. var newParentDiv = document.createElement('div');
  53. newParentDiv.className = 'jss102';
  54. newParentDiv.setAttribute('style', 'padding-left: 1rem;');
  55. newParentDiv.appendChild(createLabel());
  56.  
  57. var attempts = 0;
  58. var maxAttempts = 5;
  59.  
  60. function insertParentDiv() {
  61. if (article.firstChild) {
  62. article.insertBefore(newParentDiv, article.firstChild);
  63. } else {
  64. attempts++;
  65. if (attempts < maxAttempts) {
  66. setTimeout(insertParentDiv, 500);
  67. }
  68. }
  69. }
  70.  
  71. insertParentDiv();
  72. }
  73.  
  74. function createLabel() {
  75. var newLabel = document.createElement('label');
  76. newLabel.className = 'MuiFormControlLabel-root jss31';
  77. newLabel.innerHTML = '<span class="MuiSwitch-root">' +
  78. '<span class="MuiButtonBase-root MuiIconButton-root jss51 MuiSwitch-switchBase MuiSwitch-colorSecondary' +
  79. (isCollapsed ? '' : ' Mui-checked') + '" aria-disabled="false">' +
  80. '<span class="MuiIconButton-label">' +
  81. '<input class="jss54 MuiSwitch-input" name="checkedA" type="checkbox" value="" ' +
  82. (isCollapsed ? '' : 'checked') + '>' +
  83. '<span class="MuiSwitch-thumb"></span>' +
  84. '</span>' +
  85. '<span class="MuiTouchRipple-root"></span>' +
  86. '</span>' +
  87. '<span class="MuiSwitch-track"></span>' +
  88. '</span>' +
  89. '<span class="MuiTypography-root MuiFormControlLabel-label MuiTypography-body1">' + getLabelText() + '</span>';
  90. newLabel.querySelector('.MuiIconButton-root').addEventListener('click', function() {
  91. isCollapsed = !isCollapsed;
  92. localStorage.setItem('isCollapsed', isCollapsed);
  93. updateButton(newLabel);
  94. updateCommentSectionDisplay();
  95. hideUnrelatedElements();
  96. showTooltip(isCollapsed ? '評論區已隱藏' : '評論區已顯示');
  97. });
  98.  
  99. return newLabel;
  100. }
  101.  
  102. function updateButton(label) {
  103. var button = label.querySelector('.MuiButtonBase-root');
  104. var iconButton = label.querySelector('.MuiIconButton-root');
  105. if (isCollapsed) {
  106. button.classList.remove('Mui-checked');
  107. iconButton.classList.remove('Mui-checked');
  108. } else {
  109. button.classList.add('Mui-checked');
  110. iconButton.classList.add('Mui-checked');
  111. }
  112. label.querySelector('.MuiTypography-root').textContent = getLabelText();
  113. }
  114.  
  115. function getLabelText() {
  116. return isCollapsed ? '吐槽已收起' : '吐槽已展开';
  117. }
  118.  
  119. function updateCommentSectionDisplay() {
  120. var paperElement = document.querySelector('.MuiPaper-root.MuiCard-root.jss31.jss49.MuiPaper-elevation3.MuiPaper-rounded');
  121. if (paperElement) {
  122. paperElement.style.display = isCollapsed ? 'none' : 'block';
  123. }
  124. }
  125.  
  126. function hideUnrelatedElements() {
  127. // 隱藏無用的 .jss7 元素
  128. var jss7Div = document.querySelector('.jss7');
  129. if (jss7Div) {
  130. jss7Div.style.display = 'none';
  131. }
  132.  
  133. // 隱藏廣告元素 .jss79
  134. var jss79Div = document.querySelector('.jss79');
  135. if (jss79Div) {
  136. jss79Div.style.display = 'none';
  137. }
  138.  
  139. // 隱藏廣告元素 .jss80
  140. var jss80Div = document.querySelector('.jss80');
  141. if (jss80Div) {
  142. jss80Div.style.display = 'none';
  143. }
  144.  
  145. // 隐藏廣告元素 #google_pedestal_container
  146. var googlePedestalContainer = document.querySelector('#google_pedestal_container');
  147. if (googlePedestalContainer) {
  148. googlePedestalContainer.style.display = 'none';
  149. }
  150. }
  151.  
  152. function showTooltip(text) {
  153. var tooltip = document.createElement('div');
  154. tooltip.textContent = text;
  155. tooltip.classList.add('pagetual_tipsWords');
  156. document.body.appendChild(tooltip);
  157. tooltip.style.left = '50%';
  158. tooltip.style.top = '50%';
  159. tooltip.style.transform = 'translate(-50%, -50%)';
  160. tooltip.style.opacity = '0.6';
  161. setTimeout(function() {
  162. tooltip.style.opacity = '0';
  163. setTimeout(function() {
  164. document.body.removeChild(tooltip);
  165. }, 500);
  166. }, 2000);
  167. }
  168.  
  169. GM_addStyle(`
  170. .pagetual_tipsWords {
  171. font-size: 20px;
  172. font-weight: bold;
  173. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  174. color: #ffffff;
  175. min-height: 50px;
  176. max-width: 80%;
  177. line-height: 1.5;
  178. position: fixed;
  179. left: 50%;
  180. top: 50%;
  181. transform: translate(-50%, -50%);
  182. z-index: 2147483647;
  183. background-color: rgba(0, 0, 0, 0.8);
  184. border: 1px solid #303030;
  185. border-radius: 10px;
  186. padding: 10px;
  187. opacity: 0;
  188. pointer-events: none;
  189. text-align: center;
  190. word-break: break-all;
  191. transition: opacity 0.8s ease-in-out;
  192. white-space: nowrap;
  193. }
  194. `);
  195. })();

QingJ © 2025

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