Movable & Resizable Menu Script

A movable, resizable menu on a webpage.

  1. // ==UserScript==
  2. // @name Movable & Resizable Menu Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description A movable, resizable menu on a webpage.
  6. // @author You
  7. // @match *://*/*
  8. // @grant none
  9. // @license MrSticker23
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Helper function to get React's stateNode
  16. function getStateNode() {
  17. return Object.values((function react(r = document.querySelector("body>div")) {
  18. return Object.values(r)[1]?.children?.[0]?._owner.stateNode ? r : react(r.querySelector(":scope>div"));
  19. })())[1].children[0]._owner.stateNode;
  20. }
  21.  
  22. // Cheat definitions
  23. const Cheats = {
  24. global: {
  25. name: "Global",
  26. img: "https://media.blooket.com/image/upload/v1661496291/Media/uiTest/Games_Played_2.svg",
  27. cheats: [
  28. {
  29. name: "Auto Answer",
  30. description: "Toggles auto answer on",
  31. type: "toggle",
  32. enabled: false,
  33. data: null,
  34. run: function () {
  35. if (!this.enabled) {
  36. this.enabled = true;
  37. this.data = setInterval(() => {
  38. const stateNode = getStateNode();
  39. const Question = stateNode.state.question || stateNode.props.client.question;
  40. if (stateNode.state.question.qType != "typing") {
  41. if (stateNode.state.stage != "feedback" && !stateNode.state.feedback) {
  42. let ind;
  43. for (ind = 0; ind < Question.answers.length; ind++) {
  44. let found = false;
  45. for (let j = 0; j < Question.correctAnswers.length; j++)
  46. if (Question.answers[ind] == Question.correctAnswers[j]) {
  47. found = true;
  48. break;
  49. }
  50. if (found) break;
  51. }
  52. document.querySelectorAll("[class*='answerContainer']")[ind].click();
  53. } else document.querySelector("[class*='feedback'], [id*='feedback']").firstChild.click();
  54. } else Object.values(document.querySelector("[class*='typingAnswerWrapper']"))[1].children._owner.stateNode.sendAnswer(Question.answers[0]);
  55. }, 50);
  56. } else {
  57. this.enabled = false;
  58. clearInterval(this.data);
  59. this.data = null;
  60. }
  61. }
  62. },
  63. ]
  64. }
  65. };
  66.  
  67. // Create menu container
  68. const menu = document.createElement('div');
  69. menu.style.position = 'fixed';
  70. menu.style.top = '100px';
  71. menu.style.left = '100px';
  72. menu.style.width = '500px';
  73. menu.style.height = '400px';
  74. menu.style.backgroundColor = 'rgba(0, 0, 0, 0.9)';
  75. menu.style.color = 'white';
  76. menu.style.display = 'flex';
  77. menu.style.borderRadius = '10px';
  78. menu.style.zIndex = '1000';
  79. menu.style.cursor = 'move';
  80.  
  81. // Create sidebar
  82. const sidebar = document.createElement('div');
  83. sidebar.style.width = '120px';
  84. sidebar.style.backgroundColor = '#333';
  85. sidebar.style.display = 'flex';
  86. sidebar.style.flexDirection = 'column';
  87. sidebar.style.padding = '10px';
  88. sidebar.style.borderRight = '2px solid #555';
  89.  
  90. // Create content container (main menu area)
  91. const contentContainer = document.createElement('div');
  92. contentContainer.style.flexGrow = '1';
  93. contentContainer.style.padding = '20px';
  94.  
  95. // Sections for the content area
  96. const section1 = document.createElement('div');
  97. section1.innerHTML = '<h3>Section 1</h3><p>This is the content for section 1.</p>';
  98.  
  99. const section2 = document.createElement('div');
  100. section2.innerHTML = '<h3>Section 2</h3><p>This is the content for section 2.</p>';
  101.  
  102. const sectionCheats = document.createElement('div');
  103. sectionCheats.innerHTML = '<h3>Cheats</h3><p>Use cheats like Auto Answer below.</p>';
  104.  
  105. // Auto Answer toggle button
  106. const autoAnswerButton = document.createElement('button');
  107. autoAnswerButton.textContent = 'Toggle Auto Answer';
  108. autoAnswerButton.onclick = function() {
  109. Cheats.global.cheats[0].run();
  110. alert(`Auto Answer is now ${Cheats.global.cheats[0].enabled ? 'enabled' : 'disabled'}.`);
  111. };
  112. sectionCheats.appendChild(autoAnswerButton);
  113.  
  114. // Display the first section initially
  115. contentContainer.appendChild(section1);
  116.  
  117. // Function to switch sections
  118. function showSection(section) {
  119. contentContainer.innerHTML = '';
  120. contentContainer.appendChild(section);
  121. }
  122.  
  123. // Sidebar buttons
  124. const btn1 = document.createElement('button');
  125. btn1.textContent = 'Section 1';
  126. btn1.style.marginBottom = '10px';
  127. btn1.onclick = function() {
  128. showSection(section1);
  129. };
  130. sidebar.appendChild(btn1);
  131.  
  132. const btn2 = document.createElement('button');
  133. btn2.textContent = 'Section 2';
  134. btn2.style.marginBottom = '10px';
  135. btn2.onclick = function() {
  136. showSection(section2);
  137. };
  138. sidebar.appendChild(btn2);
  139.  
  140. const btnCheats = document.createElement('button');
  141. btnCheats.textContent = 'Cheats';
  142. btnCheats.onclick = function() {
  143. showSection(sectionCheats);
  144. };
  145. sidebar.appendChild(btnCheats);
  146.  
  147. // Append sidebar and content container to the menu
  148. menu.appendChild(sidebar);
  149. menu.appendChild(contentContainer);
  150.  
  151. // Make the menu draggable
  152. let isDragging = false;
  153. let offsetX, offsetY;
  154.  
  155. menu.addEventListener('mousedown', function(e) {
  156. isDragging = true;
  157. offsetX = e.clientX - parseInt(menu.style.left);
  158. offsetY = e.clientY - parseInt(menu.style.top);
  159. menu.style.cursor = 'grabbing';
  160. });
  161.  
  162. document.addEventListener('mousemove', function(e) {
  163. if (isDragging) {
  164. menu.style.left = (e.clientX - offsetX) + 'px';
  165. menu.style.top = (e.clientY - offsetY) + 'px';
  166. }
  167. });
  168.  
  169. document.addEventListener('mouseup', function() {
  170. isDragging = false;
  171. menu.style.cursor = 'move';
  172. });
  173.  
  174. // Append the menu to the body
  175. document.body.appendChild(menu);
  176.  
  177. })();