XP Involker

XP Free

  1. // ==UserScript==
  2. // @name XP Involker
  3. // @namespace https://greasyfork.org/en/scripts/507701-xp-involker
  4. // @version 1.75
  5. // @description XP Free
  6. // @author MrBonkeiro
  7. // @match https://bonk.io/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=bonk.io
  9. // @run-at document-idle
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. function getBonk() {
  14. const iframe = document.getElementById('maingameframe');
  15. if (!iframe) {
  16. console.error('[MrMenu] Iframe not found');
  17. return null;
  18. }
  19.  
  20. const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
  21. if (!iframeDoc) {
  22. console.error('[MrMenu] Iframe document not found');
  23. return null;
  24. }
  25.  
  26. return iframeDoc;
  27. }
  28.  
  29. function addHTML(htmlString, selector, beforeSelector = null)
  30. {
  31. const bonkDoc = getBonk();
  32. const targetElement = bonkDoc.querySelector(selector);
  33. if (!targetElement) { return; }
  34.  
  35. const parser = new DOMParser();
  36. const doc = parser.parseFromString(htmlString, 'text/html');
  37. const newElements = Array.from(doc.body.childNodes);
  38.  
  39. if (beforeSelector) {
  40. const beforeElement = bonkDoc.querySelector(beforeSelector);
  41. if (!beforeElement) { return; }
  42. newElements.forEach(node => {
  43. beforeElement.parentNode.insertBefore(node, beforeElement);
  44. });
  45. } else {
  46. newElements.forEach(node => {
  47. targetElement.appendChild(node);
  48. });
  49. }
  50. }
  51. function isRoom() {
  52. const bonkDoc = getBonk();
  53. if (!bonkDoc) return false;
  54.  
  55. const element = bonkDoc.getElementById('gamerenderer');
  56. if (element) {
  57. return window.getComputedStyle(element).visibility === 'inherit';
  58. }
  59.  
  60. return false;
  61. }
  62.  
  63. function Init() {
  64. addHTML(`<div style="background-color: #1f1f1f; display: flex; position: absolute; top: 50%; left: 50%; width: 85%; height: 85%; transform: translate(-50%, -50%); flex-direction: column; align-items: flex-start; padding: 10px;">
  65. <div style="display: flex; align-items: center; margin-bottom: 10px;">
  66. <img src="https://bonk.io/graphics/flags/us.png" alt="Imagem 1" style="width: 40px; height: 32px;">
  67. <label style="color: white; margin-left: 10px;">Download new version XP Involker no MrMenu and remove XP Involker old</label>
  68. </div>
  69. <div style="display: flex; align-items: center; margin-bottom: 10px;">
  70. <img src="https://bonk.io/graphics/flags/br.png" alt="Imagem 2" style="width: 40px; height: 32px;">
  71. <label style="color: white; margin-left: 10px;">Baixe nova versão do XP Involker in MrMenu e remova está versão velha do XP Involker</label>
  72. </div>
  73. <div style="margin-top: 10px;">
  74. <a href="https://greasyfork.org/en/scripts/504571-mrmenu/code" target="_blank" style="color: white; text-decoration: none;">Download</a>
  75. </div>
  76. </div>
  77. `, '#bonkiocontainer');
  78. let getWS;
  79. let timer = null;
  80. let deletePressed = false;
  81.  
  82. function XP()
  83. {
  84. if (isRoom && getWS != null) { getWS.send('42[38]');}
  85.  
  86. }
  87.  
  88. function handleDeleteKey(event) {
  89. if (event.key === "Delete"|| event.key === "L" || event.key === "l") {
  90. if (!deletePressed) {
  91. deletePressed = true;
  92. timer = setInterval(XP, 6000);
  93. getBonk().getElementById('xpbarfill').style.backgroundColor = 'lightgreen';
  94. } else {
  95. clearInterval(timer);
  96. deletePressed = false;
  97. getBonk().getElementById('xpbarfill').style.backgroundColor = '#473aaf';
  98.  
  99. }
  100. }
  101. }
  102.  
  103. getBonk().addEventListener("keydown", handleDeleteKey);
  104.  
  105. const originalSend = getBonk().defaultView.WebSocket.prototype.send;
  106. getBonk().defaultView.WebSocket.prototype.send = function (...args) {
  107. if (this.url.includes('socket.io')) {
  108. getWS = this;
  109.  
  110. const originalOnMessage = this.onmessage;
  111. this.onmessage = function (msg) {
  112. return originalOnMessage.call(this, msg);
  113. };
  114.  
  115. const originalOnClose = this.onclose;
  116. this.onclose = function () {
  117. getWS = null;
  118. return originalOnClose.call(this);
  119. };
  120. }
  121.  
  122. return originalSend.apply(this, args);
  123. };
  124. }
  125.  
  126. function ScriptInjector(f) {
  127. if (window.location === window.parent.location) {
  128. if (document.readyState === 'complete') {
  129. setTimeout(f, 1200);
  130. } else {
  131. document.addEventListener('readystatechange', function () {
  132. setTimeout(f, 3500);
  133. });
  134. }
  135. }
  136. }
  137.  
  138.  
  139. ScriptInjector(Init);