Time Machine

Allows you to make change the rate and direction of time flow

  1. // ==UserScript==
  2. // @name Time Machine
  3. // @id timeflower
  4. // @namespace timeflower
  5.  
  6. // @description Allows you to make change the rate and direction of time flow
  7. // @version 0.0.3-0.0.3
  8.  
  9. // @include https://kolanich.github.io/Time-Machine-userscript/
  10.  
  11. // @author KOLANICH
  12. // @copyright KOLANICH, 2015
  13. // @license Unlicensed
  14. // @contributionURL https://github.com/KOLANICH/Time-Machine-userscript
  15. // @contributionAmount feel free to fork and contribute
  16.  
  17.  
  18. // @grant GM.registerMenuCommand
  19. // @grant GM.getResourceUrl
  20. // @run-at document-start
  21. // @optimize 1
  22. // @resource inject.js ./inject.js
  23. //
  24. // ==/UserScript==
  25.  
  26. /*This is free and unencumbered software released into the public domain.
  27.  
  28. Anyone is free to copy, modify, publish, use, compile, sell, or
  29. distribute this software, either in source code form or as a compiled
  30. binary, for any purpose, commercial or non-commercial, and by any
  31. means.
  32.  
  33. In jurisdictions that recognize copyright laws, the author or authors
  34. of this software dedicate any and all copyright interest in the
  35. software to the public domain. We make this dedication for the benefit
  36. of the public at large and to the detriment of our heirs and
  37. successors. We intend this dedication to be an overt act of
  38. relinquishment in perpetuity of all present and future rights to this
  39. software under copyright law.
  40.  
  41. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  42. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  43. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  44. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  45. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  46. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  47. OTHER DEALINGS IN THE SOFTWARE.
  48.  
  49. For more information, please refer to <http://unlicense.org/>*/
  50.  
  51. "use strict";
  52. let el=document.createElement("timeshifter-signal-element");
  53. document.head.appendChild(el);
  54. let s=document.createElement("SCRIPT");
  55. GM.getResourceUrl("inject.js").then((res)=>{
  56. s.src=res;
  57. document.head.insertBefore(s, document.head.firstChild);
  58. });
  59.  
  60. let setRate=function setRate(rate){
  61. el.dispatchEvent(new CustomEvent('setRate', {detail:rate}));
  62. };
  63.  
  64. let presets= [-10,-1,0.1,0.5,1,2,10,100,1000,10000];
  65.  
  66. function createControlBox(){
  67. document.addEventListener("DOMContentLoaded", ()=>{
  68. let d=document.createElement("div");
  69. let t=document.createElement("input");
  70. t.type="number";
  71. t.required=true;
  72. t.maxlength=t.size=5;
  73. t.placeholder="1";
  74. //t.disabled=true;
  75. d.appendChild(t);
  76. let dl=document.createElement("datalist");
  77. for(let p of presets){
  78. let b=document.createElement("option");
  79. b.value=p;
  80. dl.appendChild(b);
  81. }
  82. t.appendChild(dl);
  83. t.addEventListener("change", (evt)=>{
  84. if(!evt.target.reportValidity())
  85. evt.target.value=1;
  86. setRate(evt.target.value);
  87. }, false);
  88. document.body.appendChild(d);
  89. d.style.position="fixed";
  90. d.style.top="50%";
  91. d.style.right="0px";
  92. d.style.zIndex="99999";
  93. }, false);
  94. }
  95.  
  96. if(GM.registerMenuCommand){
  97. presets.forEach((r)=>{
  98. GM.registerMenuCommand(r+"x",setRate.bind(this,r));
  99. });
  100. //GM.registerMenuCommand("Show intervals",()=>{console.log(intervals);});
  101. }else{
  102. createControlBox();
  103. }