Simple Auto-Refresh

Randomized delays auto-refresh

  1. // ==UserScript==
  2. // @name Simple Auto-Refresh
  3. // @namespace https://github.com/RustwuIf
  4. // @version 1.1.5
  5. // @description Randomized delays auto-refresh
  6. // @author Rustwulf
  7. // @match <all_urls>
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // Core settings
  16. const storageKey = 'autoRefreshState';
  17. let isRunning = false;
  18. let remainingTime = 0;
  19. let countdownInterval = null;
  20.  
  21. // Load saved values from localStorage
  22. let minDelay = parseInt(localStorage.getItem('minDelay')) || 5;
  23. let maxDelay = parseInt(localStorage.getItem('maxDelay')) || 15;
  24.  
  25. // Create UI elements
  26. const mainButton = document.createElement('button');
  27. mainButton.style.cssText = `
  28. position: fixed;
  29. bottom: 5px;
  30. left: 15px;
  31. padding: 2px 2px;
  32. background: #FF6B6B;
  33. color: white;
  34. border: none;
  35. border-radius: 8px;
  36. font-size: 20px;
  37. cursor: pointer;
  38. z-index: 99999;
  39. `;
  40. mainButton.textContent = '▶️⇧+T';
  41.  
  42. const settingsButton = document.createElement('button');
  43. settingsButton.style.cssText = `
  44. position: fixed;
  45. bottom: 5px;
  46. left: 90px;
  47. padding: 2px 2px;
  48. background: #FFFFFF;
  49. color: white;
  50. border: none;
  51. border-radius: 8px;
  52. font-size: 20px;
  53. cursor: pointer;
  54. z-index: 99999;
  55. `;
  56. settingsButton.textContent = '⚙️';
  57.  
  58. const countdownDisplay = document.createElement('div');
  59. countdownDisplay.style.cssText = `
  60. position: fixed;
  61. bottom: 37px;
  62. left: 17px;
  63. background: rgba(0,0,0,0.2);
  64. color: white;
  65. padding: 5px;
  66. border-radius: 8px;
  67. font-size: 15px;
  68. display: none;
  69. `;
  70.  
  71. const settingsModal = document.createElement('div');
  72. settingsModal.style.cssText = `
  73. position: fixed;
  74. bottom: 20px;
  75. left: 10px;
  76. width: 300px;
  77. background: Black;
  78. border: 1px solid #ccc;
  79. padding: 20px;
  80. border-radius: 8px;
  81. z-index: 99999;
  82. display: none;
  83. box-shadow: 0 0 10px rgba(0,0,0,0.3);
  84. `;
  85. settingsModal.innerHTML = `
  86. <h3 style="margin-bottom: 15px; color: white;">Settings</h3>
  87. <div style="display: flex; align-items: center; margin-bottom: 10px;">
  88. <label style="width: 120px; margin-right: 10px; color: white;">Min Delay (s):</label>
  89. <input type="number" id="minDelay" value="${minDelay}" style="padding: 6px; border: 1px solid #ddd; border-radius: 4px; width: 70px;">
  90. </div>
  91. <div style="display: flex; align-items: center; margin-bottom: 20px;">
  92. <label style="width: 120px; margin-right: 10px; color: white;">Max Delay (s):</label>
  93. <input type="number" id="maxDelay" value="${maxDelay}" style="padding: 6px; border: 1px solid #ddd; border-radius: 4px; width: 70px;">
  94. </div>
  95. <div style="display: flex; justify-content: flex-end;">
  96. <button id="saveSettings" style="padding: 8px 15px; background: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; margin-right: 10px;">Save</button>
  97. <button id="closeModal" style="padding: 8px 15px; background: #ff4d4d; color: white; border: none; border-radius: 4px; cursor: pointer;">Close</button>
  98. </div>
  99. `;
  100.  
  101. // Append to DOM
  102. document.body.appendChild(mainButton);
  103. document.body.appendChild(settingsButton);
  104. document.body.appendChild(countdownDisplay);
  105. document.body.appendChild(settingsModal);
  106.  
  107. // Event listeners
  108. mainButton.addEventListener('click', toggleAutoRefresh);
  109. settingsButton.addEventListener('click', openSettings);
  110. document.getElementById('closeModal').addEventListener('click', closeSettings);
  111. document.getElementById('saveSettings').addEventListener('click', saveSettings);
  112.  
  113. document.addEventListener('keydown', (e) => {
  114. if (e.shiftKey && e.key === 'T') {
  115. e.preventDefault();
  116. mainButton.click();
  117. }
  118. });
  119.  
  120. // Functions
  121. function toggleAutoRefresh() {
  122. isRunning = !isRunning;
  123. localStorage.setItem(storageKey, isRunning);
  124. mainButton.textContent = isRunning ? '⏸️⇧+T' : '▶️⇧+T';
  125. mainButton.style.backgroundColor = isRunning ? '#FF4444' : '#FF6B6B';
  126. isRunning ? startAutoRefresh() : clearInterval(countdownInterval);
  127. }
  128.  
  129. function openSettings() {
  130. // Update inputs to current values
  131. document.getElementById('minDelay').value = minDelay;
  132. document.getElementById('maxDelay').value = maxDelay;
  133. settingsModal.style.display = 'block';
  134. }
  135.  
  136. function closeSettings() {
  137. settingsModal.style.display = 'none';
  138. }
  139.  
  140. function saveSettings() {
  141. // Parse inputs and update variables
  142. minDelay = parseInt(document.getElementById('minDelay').value, 10) || 5;
  143. maxDelay = parseInt(document.getElementById('maxDelay').value, 10) || 15;
  144.  
  145. // Validate min <= max
  146. if (minDelay > maxDelay) {
  147. alert("Min delay cannot exceed max delay!");
  148. return;
  149. }
  150.  
  151. // Save to localStorage
  152. localStorage.setItem('minDelay', minDelay);
  153. localStorage.setItem('maxDelay', maxDelay);
  154. closeSettings();
  155. }
  156.  
  157. function startAutoRefresh() {
  158. const delay = Math.random() * (maxDelay - minDelay) + minDelay;
  159. remainingTime = Math.floor(delay);
  160. countdownDisplay.style.display = 'block';
  161. countdownInterval = setInterval(() => {
  162. if (remainingTime <= 0) {
  163. clearInterval(countdownInterval);
  164. window.location.reload();
  165. } else {
  166. remainingTime--;
  167. countdownDisplay.textContent = `🔄 ${remainingTime}s`;
  168. }
  169. }, 1000);
  170. }
  171.  
  172. // Restore state on page load
  173. window.addEventListener('load', () => {
  174. const storedState = localStorage.getItem(storageKey);
  175. if (storedState === 'true') {
  176. isRunning = true;
  177. // Directly start auto-refresh without toggling
  178. startAutoRefresh();
  179. // Update button state manually
  180. mainButton.textContent = '⏸️⇧+T';
  181. mainButton.style.backgroundColor = '#FF4444';
  182. }
  183. });
  184. })();

QingJ © 2025

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