Greasy Fork is available in English.

Hack Timer.js By Turuslan

Hack Timer js

Skrip ini tidak untuk dipasang secara langsung. Ini adalah pustaka skrip lain untuk disertakan dengan direktif meta // @require https://update.greasyfork.org/scripts/461221/1159560/Hack%20Timerjs%20By%20Turuslan.js

  1. // ==UserScript==
  2. // @license MIT
  3. // ==/UserScript==
  4.  
  5. (function (workerScript) {
  6. if (!/MSIE 10/i.test (navigator.userAgent)) {
  7. try {
  8. var blob = new Blob (["\
  9. var fakeIdToId = {};\
  10. onmessage = function (event) {\
  11. var data = event.data,\
  12. name = data.name,\
  13. fakeId = data.fakeId,\
  14. time;\
  15. if(data.hasOwnProperty('time')) {\
  16. time = data.time;\
  17. }\
  18. switch (name) {\
  19. case 'setInterval':\
  20. fakeIdToId[fakeId] = setInterval(function () {\
  21. postMessage({fakeId: fakeId});\
  22. }, time);\
  23. break;\
  24. case 'clearInterval':\
  25. if (fakeIdToId.hasOwnProperty (fakeId)) {\
  26. clearInterval(fakeIdToId[fakeId]);\
  27. delete fakeIdToId[fakeId];\
  28. }\
  29. break;\
  30. case 'setTimeout':\
  31. fakeIdToId[fakeId] = setTimeout(function () {\
  32. postMessage({fakeId: fakeId});\
  33. if (fakeIdToId.hasOwnProperty (fakeId)) {\
  34. delete fakeIdToId[fakeId];\
  35. }\
  36. }, time);\
  37. break;\
  38. case 'clearTimeout':\
  39. if (fakeIdToId.hasOwnProperty (fakeId)) {\
  40. clearTimeout(fakeIdToId[fakeId]);\
  41. delete fakeIdToId[fakeId];\
  42. }\
  43. break;\
  44. }\
  45. }\
  46. "]);
  47. // Obtain a blob URL reference to our worker 'file'.
  48. workerScript = window.URL.createObjectURL(blob);
  49. } catch (error) {
  50. /* Blob is not supported, use external script instead */
  51. }
  52. }
  53. var worker,
  54. fakeIdToCallback = {},
  55. lastFakeId = 0,
  56. maxFakeId = 0x7FFFFFFF, // 2 ^ 31 - 1, 31 bit, positive values of signed 32 bit integer
  57. logPrefix = 'HackTimer.js by turuslan: ';
  58. if (typeof (Worker) !== 'undefined') {
  59. function getFakeId () {
  60. do {
  61. if (lastFakeId == maxFakeId) {
  62. lastFakeId = 0;
  63. } else {
  64. lastFakeId ++;
  65. }
  66. } while (fakeIdToCallback.hasOwnProperty (lastFakeId));
  67. return lastFakeId;
  68. }
  69. try {
  70. worker = new Worker (workerScript);
  71. window.setInterval = function (callback, time /* , parameters */) {
  72. var fakeId = getFakeId ();
  73. fakeIdToCallback[fakeId] = {
  74. callback: callback,
  75. parameters: Array.prototype.slice.call(arguments, 2)
  76. };
  77. worker.postMessage ({
  78. name: 'setInterval',
  79. fakeId: fakeId,
  80. time: time
  81. });
  82. return fakeId;
  83. };
  84. window.clearInterval = function (fakeId) {
  85. if (fakeIdToCallback.hasOwnProperty(fakeId)) {
  86. delete fakeIdToCallback[fakeId];
  87. worker.postMessage ({
  88. name: 'clearInterval',
  89. fakeId: fakeId
  90. });
  91. }
  92. };
  93. window.setTimeout = function (callback, time /* , parameters */) {
  94. var fakeId = getFakeId ();
  95. fakeIdToCallback[fakeId] = {
  96. callback: callback,
  97. parameters: Array.prototype.slice.call(arguments, 2),
  98. isTimeout: true
  99. };
  100. worker.postMessage ({
  101. name: 'setTimeout',
  102. fakeId: fakeId,
  103. time: time
  104. });
  105. return fakeId;
  106. };
  107. window.clearTimeout = function (fakeId) {
  108. if (fakeIdToCallback.hasOwnProperty(fakeId)) {
  109. delete fakeIdToCallback[fakeId];
  110. worker.postMessage ({
  111. name: 'clearTimeout',
  112. fakeId: fakeId
  113. });
  114. }
  115. };
  116. worker.onmessage = function (event) {
  117. var data = event.data,
  118. fakeId = data.fakeId,
  119. request,
  120. parameters,
  121. callback;
  122. if (fakeIdToCallback.hasOwnProperty(fakeId)) {
  123. request = fakeIdToCallback[fakeId];
  124. callback = request.callback;
  125. parameters = request.parameters;
  126. if (request.hasOwnProperty ('isTimeout') && request.isTimeout) {
  127. delete fakeIdToCallback[fakeId];
  128. }
  129. }
  130. if (typeof (callback) === 'string') {
  131. try {
  132. callback = new Function (callback);
  133. } catch (error) {
  134. console.log (logPrefix + 'Error parsing callback code string: ', error);
  135. }
  136. }
  137. if (typeof (callback) === 'function') {
  138. callback.apply (window, parameters);
  139. }
  140. };
  141. worker.onerror = function (event) {
  142. console.log (event);
  143. };
  144. } catch (error) {
  145. console.log (logPrefix + 'Initialisation failed');
  146. console.error (error);
  147. }
  148. } else {
  149. console.log (logPrefix + 'Initialisation failed - HTML5 Web Worker is not supported');
  150. }
  151. }) ('HackTimerWorker.js');