Jstris Toggle Clean Sprint

Toggle distracting elements on and off

  1. // ==UserScript==
  2. // @name Jstris Toggle Clean Sprint
  3. // @version 2.0
  4. // @description Toggle distracting elements on and off
  5. // @author Garbaz
  6. // @match https://jstris.jezevec10.com/*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/683917
  9. // ==/UserScript==
  10. (function() {
  11.  
  12. //--------------CONFIG--------------//
  13.  
  14. const STATS_SHOW_ON_TAB = true; // Show the stats when pressing TAB
  15. const STATS_HIDE_DURING_GAME = true; // Show the stats in between rounds
  16.  
  17. const BACKGROUND_IMAGE_URL = ''; // Change this to an URL to some image to make it the background
  18.  
  19. //----------------------------------//
  20.  
  21.  
  22.  
  23. var active = false;
  24.  
  25. var navbar = document.querySelector(".navbar");
  26. var buttonsBox = document.querySelector("#buttonsBox");
  27. var gstats = document.querySelector("#gstats");
  28. var game = document.querySelector("#main");
  29. var players = document.querySelector(".players");
  30. var gameFrame = document.querySelector("#gameFrame");
  31. var lrem = document.querySelector("#lrem");
  32. var sprintText = document.querySelector("#sprintText");
  33. var practiceMenu = document.querySelector("#practiceMenu");
  34. var background = document.querySelector("#BG_only");
  35.  
  36. var pmObserver = new MutationObserver(function(mutationsList, observer) {
  37. console.log(practiceMenu.style.display);
  38. if(practiceMenu.style.display == 'none') {
  39. gstats.style.visibility = 'hidden';
  40. } else {
  41. gstats.style.visibility = '';
  42. }
  43. });
  44.  
  45. window.addEventListener('keydown', function(e) {
  46. if(e.code == "Backquote") {
  47. if(!active) {
  48. active = true;
  49. navbar.style.display = "none";
  50. players.style.display = "none";
  51. buttonsBox.style.display = "none";
  52.  
  53. gstats.style.padding = "30px 0";
  54.  
  55. game.style.position = 'fixed';
  56. game.style.left = '50%';
  57. game.style.top = '50%';
  58. game.style.transform = 'translate(-50%, -50%)';
  59. game.style.margin = '0';
  60. game.style.background = 'black';
  61. game.style.paddingTop = '100px'; // Fix for https://old.reddit.com/r/Tetris/comments/jpt4zn/clean_jstris_userscript/gbi3q2r/
  62.  
  63.  
  64. lrem.style["font-size"] = '50px';
  65. sprintText.style.visibility = 'hidden';
  66.  
  67. gameFrame.style.width = '0px';
  68.  
  69. if(STATS_HIDE_DURING_GAME) {
  70. pmObserver.observe(practiceMenu, {attributes: true, attributeFilter: ["style"]});
  71. }
  72. if(STATS_HIDE_DURING_GAME || STATS_SHOW_ON_TAB) {
  73. if(practiceMenu.style.display == 'none') {
  74. gstats.style.visibility = 'hidden';
  75. }
  76. }
  77. if(BACKGROUND_IMAGE_URL != '') {
  78. console.log('url("' + BACKGROUND_IMAGE_URL + '") !important');
  79. background.style['background-image'] = 'url("' + BACKGROUND_IMAGE_URL + '")';
  80. game.style['box-shadow'] = 'black 0px 0px 16px 16px';
  81. }
  82.  
  83. } else {
  84. active = false;
  85. navbar.style.display = '';
  86. players.style.display = '';
  87. buttonsBox.style.display = '';
  88.  
  89. gstats.style.padding = '';
  90.  
  91. game.style.position = '';
  92. game.style.left = '';
  93. game.style.top = '';
  94. game.style.transform = '';
  95. game.style.background = '';
  96. game.style.paddingTop = '';
  97.  
  98.  
  99. lrem.style.width = '';
  100. lrem.style["font-size"] = '';
  101. sprintText.style.visibility = '';
  102.  
  103. gameFrame.style.width = '950px';
  104.  
  105. if(STATS_HIDE_DURING_GAME) {
  106. pmObserver.disconnect();
  107. }
  108. if(STATS_HIDE_DURING_GAME || STATS_SHOW_ON_TAB) {
  109. gstats.style.visibility = '';
  110. }
  111.  
  112. background.style['background-image'] = '';
  113. game.style['box-shadow'] = '';
  114. }
  115. e.preventDefault();
  116. } else if (e.code == "Tab") {
  117. if(active && STATS_SHOW_ON_TAB) {
  118. gstats.style.visibility = '';
  119. e.preventDefault();
  120. }
  121. }
  122. },true);
  123.  
  124. window.addEventListener('keyup', function(e) {
  125. if (e.code == "Tab") {
  126. if(active && STATS_SHOW_ON_TAB && practiceMenu.style.display == 'none') {
  127. gstats.style.visibility = 'hidden';
  128. e.preventDefault();
  129. }
  130. }
  131. }, true);
  132. })();
  133.  
  134.  
  135.