嗨皮漫畫 - 自动翻页

自動翻頁和觸摸控制功能。

  1. // ==UserScript==
  2. // @name 嗨皮漫畫 - 自動翻頁
  3. // @name:zh-TW 嗨皮漫畫 - 自動翻頁
  4. // @name:zh-CN 嗨皮漫畫 - 自动翻页
  5. // @name:ja Happy Comics - スマートフォン用の自動ページめくり
  6. // @name:en Happy Comics - Automatic Page Turning for Mobile
  7. // @version 1.19
  8. // @description 自動翻頁和觸摸控制功能。
  9. // @description:zh-TW 自動翻頁和觸摸控制功能。
  10. // @description:zh-CN 自動翻頁和觸摸控制功能。
  11. // @description:ja Happy Comics のモバイル向け自動ページめくりおよびタッチ操作を提供します。
  12. // @description:en Provides automatic page turning and touch control for Happy Comics mobile version.
  13. // @author Scott
  14. // @match *://m.happymh.com/reads/*
  15. // @match *://m.happymh.com/*
  16. // @match *://hihimanga.com/*
  17.  
  18. // @grant unsafeWindow
  19. // @grant GM_addStyle
  20. // @namespace https://www.youtube.com/c/ScottDoha
  21. // ==/UserScript==
  22.  
  23.  
  24. (function() {
  25. 'use strict';
  26.  
  27. var isRunning = true; // 默認開啟自動翻頁(Default: Auto page turning enabled)
  28. var delayTime = 1000; // 自動翻頁延遲時間,單位:毫秒(Automatic Page Turning Delay Time, in milliseconds)
  29.  
  30. var isTouching = true; // 默認開啟觸摸控制(Default: Touch control enabled)
  31. var isScrolling = false; // 滾動狀態(Scrolling state)
  32.  
  33. var toggleRunningButton = document.createElement('button');
  34. toggleRunningButton.id = 'toggleRunningButton';
  35. toggleRunningButton.className = 'toggle-button';
  36. toggleRunningButton.innerText = '自動中';
  37. document.body.appendChild(toggleRunningButton);
  38.  
  39. var toggleTouchingButton = document.createElement('button');
  40. toggleTouchingButton.id = 'toggleTouchingButton';
  41. toggleTouchingButton.className = 'toggle-button';
  42. toggleTouchingButton.innerText = '觸摸中';
  43. document.body.appendChild(toggleTouchingButton);
  44.  
  45. // 按鈕點擊事件(Button click event)
  46. toggleRunningButton.addEventListener('click', function() {
  47. isRunning = !isRunning;
  48. toggleRunningButton.innerText = isRunning ? '自動中' : '已停止';
  49. toggleRunningButton.style.backgroundColor = isRunning ? '#4CAF50' : '#f44336'; // 根據開關狀態設置背景顏色(Set background color based on switch state)
  50. // 保存開關狀態到本地存儲(Save switch state to local storage)
  51. localStorage.setItem('isRunning', isRunning ? 'true' : 'false');
  52. });
  53.  
  54. toggleTouchingButton.addEventListener('click', function() {
  55. isTouching = !isTouching;
  56. toggleTouchingButton.innerText = isTouching ? '觸摸中' : '已停止';
  57. toggleTouchingButton.style.backgroundColor = isTouching ? '#4CAF50' : '#f44336'; // 根據開關狀態設置背景顏色(Set background color based on switch state)
  58. // 保存開關狀態到本地存儲(Save switch state to local storage)
  59. localStorage.setItem('isTouching', isTouching ? 'true' : 'false');
  60. });
  61.  
  62. // 從本地存儲加載開關狀態(Load switch state from local storage)
  63. var savedRunningState = localStorage.getItem('isRunning');
  64. if (savedRunningState !== null) {
  65. isRunning = savedRunningState === 'true';
  66. toggleRunningButton.innerText = isRunning ? '自動中' : '已停止';
  67. toggleRunningButton.style.backgroundColor = isRunning ? '#4CAF50' : '#f44336';
  68. }
  69.  
  70. var savedTouchingState = localStorage.getItem('isTouching');
  71. if (savedTouchingState !== null) {
  72. isTouching = savedTouchingState === 'true';
  73. toggleTouchingButton.innerText = isTouching ? '觸摸中' : '已停止';
  74. toggleTouchingButton.style.backgroundColor = isTouching ? '#4CAF50' : '#f44336';
  75. }
  76.  
  77. var lastTouchTime = 0;
  78. var touchCount = 0;
  79. var touchResetTimeout; // 用於延遲重置 touchCount 的定時器(Used to delay reset of touchCount)
  80.  
  81. document.addEventListener('touchstart', function(event) {
  82. if (!isTouching || isScrolling) return;
  83.  
  84. var currentTime = new Date().getTime();
  85. var timeDiff = currentTime - lastTouchTime;
  86.  
  87. clearTimeout(touchResetTimeout); // 清除之前的重置定時器(Clear previous reset timer)
  88.  
  89. if (timeDiff < 500) {
  90. touchCount++;
  91. console.log('連續點擊次數:', touchCount); // 輸出累計連續點擊次數(Output cumulative continuous click count)
  92. if (touchCount === 3) {
  93. var nextChapterButton = document.querySelector('.MuiButton-containedPrimary');
  94. if (nextChapterButton && isRunning) {
  95. nextChapterButton.removeAttribute('aria-disabled');
  96. setTimeout(function() {
  97. nextChapterButton.click();
  98. }, delayTime); // 延時點擊翻頁按鈕(Delay clicking page turning button)
  99. }
  100. } else if (touchCount === 4) {
  101. window.history.back();
  102. }
  103. } else {
  104. touchCount = 1;
  105. }
  106.  
  107. lastTouchTime = currentTime;
  108.  
  109. // 設置延遲重置定時器(Set delay reset timer)
  110. touchResetTimeout = setTimeout(function() {
  111. touchCount = 0;
  112. }, 1000); // 在一秒後重置 touchCount(Reset touchCount after one second)
  113. });
  114.  
  115. document.addEventListener('touchend', function(event) {
  116. // 不需要在這里設置 isTouching 為 false(No need to set isTouching to false here)
  117. });
  118.  
  119. window.addEventListener('scroll', function() {
  120. // 監聽滾動事件,當頁面正在滾動時設置 isScrolling 為 true,否則設置為 false
  121. isScrolling = true;
  122. clearTimeout(touchResetTimeout); // 清除重置定時器,防止誤觸
  123. setTimeout(function() {
  124. isScrolling = false;
  125. }, 250); // 在滾動停止 250 毫秒後設置 isScrolling 為 false
  126. });
  127.  
  128. // 如果自動翻頁功能已啟用(isRunning 為 true),且滾動到頁面底部,則觸發自動翻頁操作
  129. function checkAutoPageTurning() {
  130. if (isRunning) {
  131. var endMarker = document.querySelector('.css-1dzg0br-bottomScan'); // 結束標記元素
  132. if (endMarker) {
  133. var markerRect = endMarker.getBoundingClientRect();
  134. var viewportHeight = window.innerHeight || document.documentElement.clientHeight;
  135.  
  136. // 檢查是否滾動到特定元素位置
  137. if (markerRect.top <= viewportHeight) {
  138. var nextChapterButton = document.querySelector('.MuiButton-containedPrimary');
  139. if (nextChapterButton) {
  140. nextChapterButton.removeAttribute('aria-disabled'); // 移除禁用屬性
  141. setTimeout(function() {
  142. nextChapterButton.click();
  143. }, delayTime); // 延時點擊翻頁按鈕(Delay clicking page turning button)
  144. }
  145. }
  146. }
  147. }
  148. }
  149.  
  150. window.addEventListener('scroll', checkAutoPageTurning); // 添加滾動事件監聽器
  151.  
  152. // 頁面加載完成後檢查一次自動翻頁
  153. checkAutoPageTurning();
  154. })();
  155.  
  156. // CSS 樣式(CSS style)
  157. var css = `
  158. .toggle-button {
  159. position: fixed;
  160. z-index: 9999;
  161. opacity: 0.5;
  162. transition: all 0.3s ease;
  163. transform: translateX(0);
  164. border: none;
  165. border-radius: 4px;
  166. cursor: pointer;
  167. outline: none;
  168. }
  169.  
  170. #toggleRunningButton {
  171. color: white;
  172. right: 0;
  173. bottom: 20px;
  174. background-color: #4CAF50; // 默認背景顏色為綠色(Default background color is green)
  175. }
  176.  
  177. #toggleTouchingButton {
  178. color: white;
  179. right: 0;
  180. bottom: 50px;
  181. background-color: #4CAF50; // 默認背景顏色為綠色(Default background color is green)
  182. }
  183. `;
  184. var style = document.createElement('style');
  185. style.appendChild(document.createTextNode(css));
  186. document.head.appendChild(style);

QingJ © 2025

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