Bonk.io Custom Mods

Some custom enhancements to bonk.io

目前为 2022-03-17 提交的版本,查看 最新版本

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