T-Rex utilities

Utilities for elgoog t-rex

  1. // ==UserScript==
  2. // @name T-Rex utilities
  3. // @namespace Reycko.TRU
  4. // @version 0.1
  5. // @description Utilities for elgoog t-rex
  6. // @author Reycko
  7. // @match https://elgoog.im/t-rex/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=elgoog.im
  9. // @license GNU
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. function print(text) {
  17. console.log(text); // no more accidentally calling JS's print()
  18. }
  19.  
  20. const debug = false;
  21. const r = window.Runner;
  22. const inst = r.instance_;
  23. const prot = r.prototype;
  24. const gameOverScr = prot.gameOver;
  25. let oldSpd;
  26.  
  27. function setSpeed(speed) {
  28. inst.setSpeed(speed);
  29. if (debug) { print("Speed set to " + speed); }
  30. }
  31.  
  32. function speedChange(event) {
  33. if (event.target.checked) {
  34. oldSpd = inst.currentSpeed;
  35. prot.gameOver = function () { };
  36. setSpeed(1000);
  37. } else {
  38. setSpeed(oldSpd);
  39. prot.gameOver = gameOverScr;
  40. }
  41. }
  42.  
  43. const title = document.createElement('div');
  44. title.id = 'title';
  45. title.style.position = 'fixed';
  46. title.style.zIndex = '10000';
  47. title.style.bottom = '57%';
  48. title.style.left = '50%';
  49. title.style.fontSize = '20px';
  50. title.style.transform = 'translate(-50%, 57%)';
  51. title.style.display = 'flex';
  52. title.style.alignItems = 'center';
  53. title.style.justifyContent = 'center';
  54. title.innerText = 'T-REX UTILITIES';
  55. title.className = 'title';
  56.  
  57. const checkboxContainer = document.createElement('div');
  58. checkboxContainer.style.position = 'fixed';
  59. checkboxContainer.style.bottom = '55%';
  60. checkboxContainer.style.left = '50%';
  61. checkboxContainer.style.transform = 'translate(-50%, 55%)';
  62. checkboxContainer.style.display = 'flex';
  63. checkboxContainer.style.alignItems = 'center';
  64. checkboxContainer.style.justifyContent = 'center';
  65. checkboxContainer.style.zIndex = '9999';
  66.  
  67. const checkboxLabel = document.createElement('label');
  68. checkboxLabel.innerText = 'Speedhack';
  69. checkboxLabel.style.marginRight = '5px';
  70.  
  71. const checkbox = document.createElement('input');
  72. checkbox.type = 'checkbox';
  73. checkbox.addEventListener('change', speedChange);
  74. checkbox.style.marginRight = '5px';
  75.  
  76. checkboxLabel.insertBefore(checkbox, checkboxLabel.firstChild);
  77.  
  78. checkboxContainer.appendChild(checkboxLabel);
  79. document.body.appendChild(checkboxContainer);
  80.  
  81. document.body.appendChild(title);
  82. })();