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. (function() {
  12. 'use strict';
  13. function findAndClickElementById() {
  14. const elementId = '#layma_me_vuatraffic';
  15. const element = document.querySelector(elementId);
  16. if (element) {
  17. console.log(`Element found: ${elementId}`);
  18. element.scrollIntoView();
  19. setTimeout(() => {
  20. element.click();
  21. console.log("Scrolled to and clicked on the element.");
  22. }, 1000); // Đợi 1 giây trước khi click
  23. } else {
  24. console.log(`Element not found: ${elementId}`);
  25. }
  26. }
  27. function activateSpeedUpTime() {
  28. console.log("Activating Speed Up Time");
  29. let speedConfig = {
  30. speed: 100.0,
  31. cbSetIntervalChecked: true,
  32. cbSetTimeoutChecked: true,
  33. cbPerformanceNowChecked: true,
  34. cbDateNowChecked: true,
  35. cbRequestAnimationFrameChecked: true,
  36. };
  37. const emptyFunction = () => {};
  38. const originalClearInterval = window.clearInterval;
  39. const originalclearTimeout = window.clearTimeout;
  40. const originalSetInterval = window.setInterval;
  41. const originalSetTimeout = window.setTimeout;
  42. const originalPerformanceNow = window.performance.now.bind(
  43. window.performance
  44. );
  45. const originalDateNow = Date.now;
  46. const originalRequestAnimationFrame = window.requestAnimationFrame;
  47. let timers = [];
  48. const reloadTimers = () => {
  49. console.log(timers);
  50. const newtimers = [];
  51. timers.forEach((timer) => {
  52. originalClearInterval(timer.id);
  53. if (timer.customTimerId) {
  54. originalClearInterval(timer.customTimerId);
  55. }
  56. if (!timer.finished) {
  57. const newTimerId = originalSetInterval(
  58. timer.handler,
  59. speedConfig.cbSetIntervalChecked
  60. ? timer.timeout / speedConfig.speed
  61. : timer.timeout,
  62. ...timer.args
  63. );
  64. timer.customTimerId = newTimerId;
  65. newtimers.push(timer);
  66. }
  67. });
  68. timers = newtimers;
  69. };
  70. window.addEventListener("message", (e) => {
  71. if (e.data.command === "setSpeedConfig") {
  72. speedConfig = e.data.config;
  73. reloadTimers();
  74. }
  75. });
  76. window.postMessage({ command: "getSpeedConfig" });
  77. window.clearInterval = (id) => {
  78. originalClearInterval(id);
  79. timers.forEach((timer) => {
  80. if (timer.id == id) {
  81. timer.finished = true;
  82. if (timer.customTimerId) {
  83. originalClearInterval(timer.customTimerId);
  84. }
  85. }
  86. });
  87. };
  88. window.clearTimeout = (id) => {
  89. originalclearTimeout(id);
  90. timers.forEach((timer) => {
  91. if (timer.id == id) {
  92. timer.finished = true;
  93. if (timer.customTimerId) {
  94. originalclearTimeout(timer.customTimerId);
  95. }
  96. }
  97. });
  98. };
  99. window.setInterval = (handler, timeout, ...args) => {
  100. console.log("timeout ", timeout);
  101. if (!timeout) timeout = 0;
  102. const id = originalSetInterval(
  103. handler,
  104. speedConfig.cbSetIntervalChecked ? timeout / speedConfig.speed : timeout,
  105. ...args
  106. );
  107. timers.push({
  108. id: id,
  109. handler: handler,
  110. timeout: timeout,
  111. args: args,
  112. finished: false,
  113. customTimerId: null,
  114. });
  115. return id;
  116. };
  117. window.setTimeout = (handler, timeout, ...args) => {
  118. if (!timeout) timeout = 0;
  119. return originalSetTimeout(
  120. handler,
  121. speedConfig.cbSetTimeoutChecked ? timeout / speedConfig.speed : timeout,
  122. ...args
  123. );
  124. };
  125. // performance.now
  126. (function () {
  127. let performanceNowValue = null;
  128. let previousPerformanceNowValue = null;
  129. window.performance.now = () => {
  130. const originalValue = originalPerformanceNow();
  131. if (performanceNowValue) {
  132. performanceNowValue +=
  133. (originalValue - previousPerformanceNowValue) *
  134. (speedConfig.cbPerformanceNowChecked ? speedConfig.speed : 1);
  135. } else {
  136. performanceNowValue = originalValue;
  137. }
  138. previousPerformanceNowValue = originalValue;
  139. return Math.floor(performanceNowValue);
  140. };
  141. })();
  142. // Date.now
  143. (function () {
  144. let dateNowValue = null;
  145. let previousDateNowValue = null;
  146. Date.now = () => {
  147. const originalValue = originalDateNow();
  148. if (dateNowValue) {
  149. dateNowValue +=
  150. (originalValue - previousDateNowValue) *
  151. (speedConfig.cbDateNowChecked ? speedConfig.speed : 1);
  152. } else {
  153. dateNowValue = originalValue;
  154. }
  155. previousDateNowValue = originalValue;
  156. return Math.floor(dateNowValue);
  157. };
  158. })();
  159. // requestAnimationFrame
  160. (function () {
  161. let dateNowValue = null;
  162. let previousDateNowValue = null;
  163. const callbackFunctions = [];
  164. const callbackTick = [];
  165. const newRequestAnimationFrame = (callback) => {
  166. return originalRequestAnimationFrame((timestamp) => {
  167. const originalValue = originalDateNow();
  168. if (dateNowValue) {
  169. dateNowValue +=
  170. (originalValue - previousDateNowValue) *
  171. (speedConfig.cbRequestAnimationFrameChecked
  172. ? speedConfig.speed
  173. : 1);
  174. } else {
  175. dateNowValue = originalValue;
  176. }
  177. previousDateNowValue = originalValue;
  178. const dateNowValue_MathFloor = Math.floor(dateNowValue);
  179. const index = callbackFunctions.indexOf(callback);
  180. let tickFrame = null;
  181. if (index === -1) {
  182. callbackFunctions.push(callback);
  183. callbackTick.push(0);
  184. callback(dateNowValue_MathFloor);
  185. } else if (speedConfig.cbRequestAnimationFrameChecked) {
  186. tickFrame = callbackTick[index];
  187. tickFrame += speedConfig.speed;
  188. if (tickFrame >= 1) {
  189. while (tickFrame >= 1) {
  190. callback(dateNowValue_MathFloor);
  191. window.requestAnimationFrame = emptyFunction;
  192. tickFrame -= 1;
  193. }
  194. window.requestAnimationFrame = newRequestAnimationFrame;
  195. } else {
  196. window.requestAnimationFrame(callback);
  197. }
  198. callbackTick[index] = tickFrame;
  199. } else {
  200. callback(dateNowValue_MathFloor);
  201. }
  202. });
  203. };
  204. window.requestAnimationFrame = newRequestAnimationFrame;
  205. })();
  206. }
  207.  
  208. // Gọi hàm để kiểm tra và click
  209. findAndClickElementById();
  210.  
  211. // Vòng lặp while để gọi activateSpeedUpTime mỗi 1 giây
  212. let intervalId = setInterval(() => {
  213. activateSpeedUpTime();
  214. }, 1000);
  215. })();