小说阅读自动滚动

一个阅读APP网页端自动滚动功能

  1. // ==UserScript==
  2. // @name 小说阅读自动滚动
  3. // @description 一个阅读APP网页端自动滚动功能
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.1
  6. // @author You
  7. // @match http://*/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license MIT
  11. // @resource css https://cdnjs.cloudflare.com/ajax/libs/antd/4.17.0/antd.min.css
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. var isScrolling = false;
  18. var intervalId;
  19. var scrollSpeed = 25; // Default scroll speed (milliseconds per scroll)
  20. var scrollPixels = 1; // Default scroll amount (pixels per scroll)
  21. var isConfigPanelOpen = false;
  22.  
  23. function startScrolling() {
  24. if (!isScrolling) {
  25. isScrolling = true;
  26. intervalId = setInterval(function() {
  27. window.scrollBy(0, scrollPixels);
  28. if (isAtBottom()) {
  29. window.scrollBy(0, 1); // Scroll one more pixel to prevent getting stuck at the bottom
  30. }
  31. }, scrollSpeed);
  32. }
  33. }
  34.  
  35. function stopScrolling() {
  36. if (isScrolling) {
  37. isScrolling = false;
  38. clearInterval(intervalId);
  39. }
  40. }
  41.  
  42. function toggleScrolling() {
  43. if (isScrolling) {
  44. stopScrolling();
  45. } else {
  46. startScrolling();
  47. }
  48. updateButtonState();
  49. }
  50.  
  51. function updateButtonState() {
  52. var scrollButton = document.getElementById('scrollButton');
  53. if (isScrolling) {
  54. scrollButton.innerText = '停止滚动';
  55. scrollButton.style.backgroundColor = '#FF0000';
  56. } else {
  57. scrollButton.innerText = '开始滚动';
  58. scrollButton.style.backgroundColor = '#007BFF';
  59. }
  60. document.getElementById('scrollStatus').innerText = isScrolling ? '状态:正在滚动' : '状态:停止滚动';
  61. }
  62.  
  63. function updateScrollConfig() {
  64. var speedInput = document.getElementById('scrollSpeedInput');
  65. var pixelsInput = document.getElementById('scrollPixelsInput');
  66.  
  67. scrollSpeed = parseInt(speedInput.value) || scrollSpeed;
  68. scrollPixels = parseInt(pixelsInput.value) || scrollPixels;
  69. }
  70.  
  71. function isAtBottom() {
  72. // Check if we are at the bottom of the page
  73. return window.innerHeight + window.scrollY >= document.body.scrollHeight;
  74. }
  75.  
  76. function toggleConfigPanel() {
  77. var configPanel = document.getElementById('configPanel');
  78. var configButton = document.getElementById('configButton');
  79. isConfigPanelOpen = !isConfigPanelOpen;
  80. configPanel.style.display = isConfigPanelOpen ? 'block' : 'none';
  81. configButton.innerText = isConfigPanelOpen ? '收起' : '配置';
  82.  
  83. // Adjust the position of the buttons based on the config panel state
  84. var scrollButton = document.getElementById('scrollButton');
  85. scrollButton.style.right = isConfigPanelOpen ? '310px' : '10px';
  86.  
  87. var statusDiv = document.getElementById('statusDiv');
  88. statusDiv.style.right = isConfigPanelOpen ? '310px' : '10px';
  89. }
  90.  
  91. function addButton() {
  92. var configDiv = document.createElement('div');
  93. configDiv.style.position = 'fixed';
  94. configDiv.style.bottom = '50%';
  95. configDiv.style.right = isConfigPanelOpen ? '300px' : '0';
  96. configDiv.style.transform = 'translateY(50%)';
  97. configDiv.style.zIndex = '9999';
  98. configDiv.style.padding = '20px';
  99. configDiv.style.background = '#ffffff';
  100. configDiv.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.2)';
  101. configDiv.style.borderRadius = isConfigPanelOpen ? '5px 0 0 5px' : '5px';
  102. configDiv.className = 'ant-card';
  103. configDiv.id = 'configPanel';
  104. configDiv.style.display = 'none';
  105.  
  106. var configButton = document.createElement('button');
  107. configButton.textContent = '收起';
  108. configButton.style.position = 'absolute';
  109. configButton.style.top = '10px';
  110. configButton.style.right = '10px';
  111. configButton.style.backgroundColor = '#007BFF';
  112. configButton.style.color = '#fff';
  113. configButton.style.border = 'none';
  114. configButton.style.borderRadius = '5px';
  115. configButton.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.2)';
  116. configButton.addEventListener('click', toggleConfigPanel);
  117. configDiv.appendChild(configButton);
  118.  
  119. var scrollButton = document.createElement('button');
  120. scrollButton.textContent = '开始滚动';
  121. scrollButton.style.marginTop = '30px';
  122. scrollButton.style.padding = '10px 20px';
  123. scrollButton.style.backgroundColor = '#007BFF';
  124. scrollButton.style.color = '#fff';
  125. scrollButton.style.border = 'none';
  126. scrollButton.style.borderRadius = '5px';
  127. scrollButton.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.2)';
  128. scrollButton.id = 'scrollButton';
  129. scrollButton.addEventListener('click', toggleScrolling);
  130. configDiv.appendChild(scrollButton);
  131.  
  132. var scrollStatus = document.createElement('div');
  133. scrollStatus.textContent = '状态:停止滚动';
  134. scrollStatus.id = 'scrollStatus';
  135. scrollStatus.style.marginTop = '10px';
  136. configDiv.appendChild(scrollStatus);
  137.  
  138. var speedLabel = document.createElement('label');
  139. speedLabel.textContent = '滚动速度 (毫秒/次): ';
  140. var speedInput = document.createElement('input');
  141. speedInput.type = 'number';
  142. speedInput.min = '1';
  143. speedInput.value = scrollSpeed.toString();
  144. speedInput.id = 'scrollSpeedInput';
  145. speedInput.className = 'ant-input';
  146. speedInput.addEventListener('change', updateScrollConfig);
  147.  
  148. var pixelsLabel = document.createElement('label');
  149. pixelsLabel.textContent = '滚动像素 (像素/次): ';
  150. var pixelsInput = document.createElement('input');
  151. pixelsInput.type = 'number';
  152. pixelsInput.min = '1';
  153. pixelsInput.value = scrollPixels.toString();
  154. pixelsInput.id = 'scrollPixelsInput';
  155. pixelsInput.className = 'ant-input';
  156. pixelsInput.addEventListener('change', updateScrollConfig);
  157.  
  158. configDiv.appendChild(speedLabel);
  159. configDiv.appendChild(speedInput);
  160. configDiv.appendChild(document.createElement('br'));
  161. configDiv.appendChild(pixelsLabel);
  162. configDiv.appendChild(pixelsInput);
  163.  
  164. document.body.appendChild(configDiv);
  165. }
  166.  
  167. function addConfigButton() {
  168. var configButton = document.createElement('button');
  169. configButton.textContent = '配置';
  170. configButton.style.position = 'fixed';
  171. configButton.style.bottom = '50%';
  172. configButton.style.right = '0';
  173. configButton.style.transform = 'translateY(50%)';
  174. configButton.style.zIndex = '9999';
  175. configButton.style.padding = '10px 15px';
  176. configButton.style.backgroundColor = '#007BFF';
  177. configButton.style.color = '#fff';
  178. configButton.style.border = 'none';
  179. configButton.style.borderRadius = '5px';
  180. configButton.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.2)';
  181. configButton.id = 'configButton';
  182. configButton.addEventListener('click', toggleConfigPanel);
  183. document.body.appendChild(configButton);
  184. }
  185.  
  186. addConfigButton();
  187. addButton();
  188. })();
  189.  
  190.  

QingJ © 2025

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