TimerHooker Android MD3 Version

Speeds up countdown timers with a fully movable UI designed for Android screens.

目前为 2025-04-03 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name TimerHooker Android MD3 Version
  3. // @version 2.3.0
  4. // @description Speeds up countdown timers with a fully movable UI designed for Android screens.
  5. // @include *
  6. // @author Govindarajulu
  7. // @match http://*/*
  8. // @run-at document-start
  9. // @grant none
  10. // @license GPL-3.0-or-later
  11. // @namespace https://greasyfork.org/users/1356925
  12. // ==/UserScript==
  13.  
  14. (function (global) {
  15. let isSpeedActive = false;
  16. const speedMultiplier = 50;
  17. let autoHideTimeout;
  18.  
  19. function overrideTimers(factor) {
  20. ["setTimeout", "setInterval"].forEach((method) => {
  21. window[method] = ((original) => (fn, time) => original(fn, time / factor))(window[method]);
  22. });
  23. }
  24.  
  25. const TimerHooker = {
  26. toggleSpeed: function () {
  27. isSpeedActive = !isSpeedActive;
  28. overrideTimers(isSpeedActive ? speedMultiplier : 1);
  29.  
  30. const btn = document.getElementById("toggleSpeedBtn");
  31. if (btn) btn.textContent = isSpeedActive ? "Stop" : "Speed";
  32.  
  33. console.log(`[TimerHooker] Countdown timers accelerated: x${isSpeedActive ? speedMultiplier : 1}`);
  34. TimerHooker.resetAutoHide(); // Reset hide timer when toggled
  35. },
  36.  
  37. createUI: function () {
  38. if (document.getElementById("timerHookerUI")) return;
  39.  
  40. const speedControl = document.createElement("div");
  41. speedControl.id = "timerHookerUI";
  42. speedControl.style = `
  43. position: fixed; top: 50%; left: -35px; z-index: 99999;
  44. background: rgba(0,0,0,0.3); color: white; padding: 6px 12px; border-radius: 40px;
  45. font-size: 12px; font-weight: 500; text-align: center; cursor: grab;
  46. backdrop-filter: blur(8px); box-shadow: 0px 3px 8px rgba(0,0,0,0.2);
  47. user-select: none; transition: left 0.3s ease, top 0.1s ease, background 0.3s ease, color 0.3s ease;
  48. touch-action: none;
  49. `;
  50.  
  51. speedControl.textContent = "Speed";
  52. speedControl.id = "toggleSpeedBtn";
  53. speedControl.addEventListener("click", () => {
  54. speedControl.style.left = "10px"; // Bring button fully into view
  55. TimerHooker.toggleSpeed();
  56. });
  57.  
  58. // Enable **touch-based dragging** across Android screens
  59. let startX, startY, isDragging = false;
  60.  
  61. speedControl.addEventListener("touchstart", (e) => {
  62. isDragging = true;
  63. clearTimeout(autoHideTimeout); // Stop auto-hide when dragged
  64. const touch = e.touches[0];
  65. startX = touch.clientX - speedControl.getBoundingClientRect().left;
  66. startY = touch.clientY - speedControl.getBoundingClientRect().top;
  67. speedControl.style.cursor = "grabbing";
  68. });
  69.  
  70. document.addEventListener("touchmove", (e) => {
  71. if (!isDragging) return;
  72. const touch = e.touches[0];
  73.  
  74. speedControl.style.left = `${Math.min(window.innerWidth - speedControl.offsetWidth, Math.max(0, touch.clientX - startX))}px`;
  75. speedControl.style.top = `${Math.min(window.innerHeight - speedControl.offsetHeight, Math.max(0, touch.clientY - startY))}px`;
  76. });
  77.  
  78. document.addEventListener("touchend", () => {
  79. isDragging = false;
  80. speedControl.style.cursor = "grab";
  81. TimerHooker.resetAutoHide(); // Start hiding after movement stops
  82. });
  83.  
  84. document.body.appendChild(speedControl);
  85. TimerHooker.resetAutoHide();
  86. console.log("[TimerHooker] UI optimized for Android successfully.");
  87. },
  88.  
  89. resetAutoHide: function () {
  90. clearTimeout(autoHideTimeout);
  91. autoHideTimeout = setTimeout(() => {
  92. const speedControl = document.getElementById("timerHookerUI");
  93. if (!isDragging) speedControl.style.left = "-35px"; // Move button back to sideline
  94. }, 3000);
  95. },
  96.  
  97. handleFullscreen: function () {
  98. document.addEventListener("fullscreenchange", () => {
  99. const speedControl = document.getElementById("timerHookerUI");
  100. if (document.fullscreenElement) {
  101. speedControl.style.display = "none"; // Hide in fullscreen mode
  102. } else {
  103. speedControl.style.display = "block"; // Show when fullscreen exits
  104. }
  105. });
  106. },
  107.  
  108. init: function () {
  109. console.log("[TimerHooker] Android MD3 version activated");
  110. this.createUI();
  111. this.handleFullscreen();
  112. }
  113. };
  114.  
  115. if (document.readyState === "complete") {
  116. TimerHooker.init();
  117. } else {
  118. window.addEventListener("load", () => TimerHooker.init());
  119. }
  120. })(window);