Greasy Fork is available in English.

Speed Up Time Script

Tăng tốc thời gian trên trang web khi nhấp vào phần tử cụ thể

  1. // ==UserScript==
  2. // @name Speed Up Time Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Tăng tốc thời gian trên trang web khi nhấp vào phần tử cụ thể
  6. // @author Your Name
  7. // @match *://*/*
  8. // @grant none
  9. // @license Hi
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function findAndClickElementById() {
  16. const elementId = '#layma_me_vuatraffic';
  17. const timeout = 10000; // Thời gian chờ tối đa là 10 giây
  18. const startTime = Date.now();
  19.  
  20. function tryFindElement() {
  21. const element = document.querySelector(elementId);
  22.  
  23. if (element) {
  24. console.log(`Element found: ${elementId}`);
  25. element.scrollIntoView();
  26. setTimeout(() => {
  27. element.click();
  28. console.log("Scrolled to and clicked on the element.");
  29. }, 1000); // Đợi 1 giây trước khi click
  30. } else if (Date.now() - startTime < timeout) {
  31. // Nếu chưa hết thời gian chờ thì thử lại
  32. setTimeout(tryFindElement, 500); // Kiểm tra lại sau 500ms
  33. } else {
  34. console.log(`Element not found after 10 seconds: ${elementId}`);
  35. }
  36. }
  37.  
  38. tryFindElement();
  39. }
  40.  
  41. function activateSpeedUpTime() {
  42. console.log("Activating Speed Up Time");
  43.  
  44. let speedConfig = {
  45. speed: 100.0,
  46. cbSetIntervalChecked: true,
  47. cbSetTimeoutChecked: true,
  48. cbPerformanceNowChecked: true,
  49. cbDateNowChecked: true,
  50. cbRequestAnimationFrameChecked: true,
  51. };
  52.  
  53. const emptyFunction = () => {};
  54.  
  55. const originalClearInterval = window.clearInterval;
  56. const originalclearTimeout = window.clearTimeout;
  57.  
  58. const originalSetInterval = window.setInterval;
  59. const originalSetTimeout = window.setTimeout;
  60.  
  61. const originalPerformanceNow = window.performance.now.bind(
  62. window.performance
  63. );
  64.  
  65. const originalDateNow = Date.now;
  66.  
  67. const originalRequestAnimationFrame = window.requestAnimationFrame;
  68.  
  69. let timers = [];
  70. const reloadTimers = () => {
  71. console.log(timers);
  72. const newtimers = [];
  73. timers.forEach((timer) => {
  74. originalClearInterval(timer.id);
  75. if (timer.customTimerId) {
  76. originalClearInterval(timer.customTimerId);
  77. }
  78. if (!timer.finished) {
  79. const newTimerId = originalSetInterval(
  80. timer.handler,
  81. speedConfig.cbSetIntervalChecked
  82. ? timer.timeout / speedConfig.speed
  83. : timer.timeout,
  84. ...timer.args
  85. );
  86. timer.customTimerId = newTimerId;
  87. newtimers.push(timer);
  88. }
  89. });
  90. timers = newtimers;
  91. };
  92.  
  93. window.addEventListener("message", (e) => {
  94. if (e.data.command === "setSpeedConfig") {
  95. speedConfig = e.data.config;
  96. reloadTimers();
  97. }
  98. });
  99.  
  100. window.postMessage({ command: "getSpeedConfig" });
  101.  
  102. window.clearInterval = (id) => {
  103. originalClearInterval(id);
  104. timers.forEach((timer) => {
  105. if (timer.id == id) {
  106. timer.finished = true;
  107. if (timer.customTimerId) {
  108. originalClearInterval(timer.customTimerId);
  109. }
  110. }
  111. });
  112. };
  113.  
  114. window.clearTimeout = (id) => {
  115. originalclearTimeout(id);
  116. timers.forEach((timer) => {
  117. if (timer.id == id) {
  118. timer.finished = true;
  119. if (timer.customTimerId) {
  120. originalclearTimeout(timer.customTimerId);
  121. }
  122. }
  123. });
  124. };
  125.  
  126. window.setInterval = (handler, timeout, ...args) => {
  127. console.log("timeout ", timeout);
  128. if (!timeout) timeout = 0;
  129. const id = originalSetInterval(
  130. handler,
  131. speedConfig.cbSetIntervalChecked ? timeout / speedConfig.speed : timeout,
  132. ...args
  133. );
  134. timers.push({
  135. id: id,
  136. handler: handler,
  137. timeout: timeout,
  138. args: args,
  139. finished: false,
  140. customTimerId: null,
  141. });
  142. return id;
  143. };
  144.  
  145. window.setTimeout = (handler, timeout, ...args) => {
  146. if (!timeout) timeout = 0;
  147. return originalSetTimeout(
  148. handler,
  149. speedConfig.cbSetTimeoutChecked ? timeout / speedConfig.speed : timeout,
  150. ...args
  151. );
  152. };
  153.  
  154. // performance.now
  155. (function () {
  156. let performanceNowValue = null;
  157. let previousPerformanceNowValue = null;
  158. window.performance.now = () => {
  159. const originalValue = originalPerformanceNow();
  160. if (performanceNowValue) {
  161. performanceNowValue +=
  162. (originalValue - previousPerformanceNowValue) *
  163. (speedConfig.cbPerformanceNowChecked ? speedConfig.speed : 1);
  164. } else {
  165. performanceNowValue = originalValue;
  166. }
  167. previousPerformanceNowValue = originalValue;
  168. return Math.floor(performanceNowValue);
  169. };
  170. })();
  171.  
  172. // Date.now
  173. (function () {
  174. let dateNowValue = null;
  175. let previousDateNowValue = null;
  176. Date.now = () => {
  177. const originalValue = originalDateNow();
  178. if (dateNowValue) {
  179. dateNowValue +=
  180. (originalValue - previousDateNowValue) *
  181. (speedConfig.cbDateNowChecked ? speedConfig.speed : 1);
  182. } else {
  183. dateNowValue = originalValue;
  184. }
  185. previousDateNowValue = originalValue;
  186. return Math.floor(dateNowValue);
  187. };
  188. })();
  189.  
  190. // requestAnimationFrame
  191. (function () {
  192. let dateNowValue = null;
  193. let previousDateNowValue = null;
  194. const callbackFunctions = [];
  195. const callbackTick = [];
  196. const newRequestAnimationFrame = (callback) => {
  197. return originalRequestAnimationFrame((timestamp) => {
  198. const originalValue = originalDateNow();
  199. if (dateNowValue) {
  200. dateNowValue +=
  201. (originalValue - previousDateNowValue) *
  202. (speedConfig.cbRequestAnimationFrameChecked
  203. ? speedConfig.speed
  204. : 1);
  205. } else {
  206. dateNowValue = originalValue;
  207. }
  208. previousDateNowValue = originalValue;
  209.  
  210. const dateNowValue_MathFloor = Math.floor(dateNowValue);
  211.  
  212. const index = callbackFunctions.indexOf(callback);
  213. let tickFrame = null;
  214. if (index === -1) {
  215. callbackFunctions.push(callback);
  216. callbackTick.push(0);
  217. callback(dateNowValue_MathFloor);
  218. } else if (speedConfig.cbRequestAnimationFrameChecked) {
  219. tickFrame = callbackTick[index];
  220. tickFrame += speedConfig.speed;
  221.  
  222. if (tickFrame >= 1) {
  223. while (tickFrame >= 1) {
  224. callback(dateNowValue_MathFloor);
  225. window.requestAnimationFrame = emptyFunction;
  226. tickFrame -= 1;
  227. }
  228. window.requestAnimationFrame = newRequestAnimationFrame;
  229. } else {
  230. window.requestAnimationFrame(callback);
  231. }
  232. callbackTick[index] = tickFrame;
  233. } else {
  234. callback(dateNowValue_MathFloor);
  235. }
  236. });
  237. };
  238. window.requestAnimationFrame = newRequestAnimationFrame;
  239. })();
  240. }
  241.  
  242. // Gọi hàm để kiểm tra và click
  243. findAndClickElementById();
  244.  
  245. // Vòng lặp while để gọi activateSpeedUpTime mỗi 1 giây
  246. let intervalId = setInterval(() => {
  247. activateSpeedUpTime();
  248. }, 1000);
  249. })();