Bonk.io Custom Mods

Some custom enhancements to bonk.io

  1. // ==UserScript==
  2. // @name Bonk.io Custom Mods
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description Some custom enhancements to bonk.io
  6. // @author You
  7. // @match https://bonk.io/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /* jshint esversion:6 */
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. const pd_func = document.getElementById('maingameframe').contentWindow.Event.prototype.preventDefault;
  17.  
  18. document.getElementById('maingameframe').contentWindow.Event.prototype.preventDefault = function() {
  19. const ev = this;
  20. if (ev.ctrlKey || ev.shiftKey || (ev.key?.[0] === 'F' && ev.key?.length > 1)) return;
  21. const bound_pd = pd_func.bind(ev);
  22. bound_pd();
  23. };
  24.  
  25. let style1 = `
  26. <style>
  27. body { overflow: hidden; }
  28. #bonkioheader { display: none; }
  29. #adboxverticalleftCurse { display: none; }
  30. #adboxverticalCurse { display: none; }
  31. #descriptioncontainer { display: none; }
  32. #maingameframe { margin: 0 !important; }
  33. </style>
  34. `;
  35. document.head.insertAdjacentHTML("beforeend", style1);
  36.  
  37. window.addEventListener('load', () => {
  38. let frame = document.getElementById('maingameframe');
  39. let frameDoc = document.getElementById('maingameframe').contentDocument;
  40.  
  41. let setup;
  42. let observer = new MutationObserver((mutations, me) => {
  43. if (frameDoc.getElementById('roomlisttopbar')) {
  44. me.disconnect(); // stop observing
  45. setup();
  46. return;
  47. }
  48. });
  49. observer.observe(frameDoc, {
  50. childList: true,
  51. subtree: true
  52. });
  53.  
  54. setup = () => {
  55. /*
  56. let style1 = `
  57. <style>
  58. body { overflow: hidden; }
  59. #bonkioheader { display: none; }
  60. #adboxverticalleftCurse { display: none; }
  61. #adboxverticalCurse { display: none; }
  62. #descriptioncontainer { display: none; }
  63. #maingameframe { margin: 0 !important; }
  64. </style>
  65. `;
  66. document.head.insertAdjacentHTML("beforeend", style1);
  67. */
  68. let placeholderStyler = `
  69. <style>
  70. [contenteditable=true]:empty:before {
  71. content: attr(placeholder);
  72. pointer-events: none;
  73. display: block; /* For Firefox */
  74. color: #757575;
  75. }
  76. </style>
  77. `;
  78. frameDoc.head.insertAdjacentHTML("beforeend", placeholderStyler);
  79.  
  80. console.log(document.head);
  81.  
  82. let $ = frame.contentWindow.$;
  83.  
  84. function filterRooms(s) {
  85. s = s.toLowerCase();
  86. let matches = el => el.children[0].textContent.toLowerCase().includes(s);
  87. $('#roomlisttable tr').each((i, el) => {
  88. el.hidden = !matches(el);
  89. });
  90. }
  91.  
  92. let inp = `<span contentEditable="true" type="text" id="roomSearchInputBox" placeholder="Search Rooms.." style="
  93. float: right;
  94. padding: 2px 8px;
  95. margin: 5px 20px;
  96. border: 2px solid #006157;
  97. border-radius: 5px;
  98. font: large futurept_b1;
  99. width: 20%;
  100. background: white;
  101. "></span>`;
  102.  
  103. $('#roomlisttopbar').append(inp);
  104.  
  105. function debounce (fn) {
  106.  
  107. // Setup a timer
  108. let timeout;
  109.  
  110. // Return a function to run debounced
  111. return function () {
  112.  
  113. // Setup the arguments
  114. let context = this;
  115. let args = arguments;
  116.  
  117. // If there's a timer, cancel it
  118. if (timeout) {
  119. window.cancelAnimationFrame(timeout);
  120. }
  121.  
  122. // Setup the new requestAnimationFrame()
  123. timeout = window.requestAnimationFrame(function () {
  124. fn.apply(context, args);
  125. });
  126.  
  127. };
  128.  
  129. }
  130.  
  131. $('#roomSearchInputBox').keyup(debounce(ev => filterRooms(ev.target.textContent)));
  132.  
  133. $('body').keydown(debounce(ev => {
  134. if (ev.altKey) {
  135. if (ev.key === 'q' && $('#roomListContainer')[0].offsetParent === null) {
  136. $('#pretty_top_exit').click(); $('#leaveconfirmwindow_okbutton').click();
  137. }
  138. else if (ev.key === 'r') {$('#roomlistrefreshbutton').click();}
  139. }
  140. if (ev.key === '/') $('#roomSearchInputBox').focus();
  141. }));
  142.  
  143. /****** Implemented by Chaz *******
  144.  
  145. // Can double click room to trigger join
  146. let room_join_dblclick_handler = (ev) => $("#roomlistjoinbutton").click();
  147. $("#roomlisttable").on("dblclick", "tr", room_join_dblclick_handler);
  148.  
  149. // Press enter to submit password for joining room
  150. let room_pass_enter_handler = (ev) => {
  151. ev.key === "Enter" && $("#roomlistpassjoinbutton").click();
  152. };
  153. $("#roomlistjoinpasswordtext").on("keydown", room_pass_enter_handler);
  154. *******/
  155. };
  156. });
  157. })();