Bonk2.io Custom Mods

Some custom enhancements to bonk.io

当前为 2021-06-08 提交的版本,查看 最新版本

// ==UserScript==
// @name         Bonk2.io Custom Mods
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Some custom enhancements to bonk.io
// @author       You
// @match        https://bonk.io/
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @grant        none
// jshint        esversion:6
// ==/UserScript==

/* globals $ */


(function () {
    'use strict';

//        $('#bonkioheader').hide();
//        $('#maingameframe').css({"position":"absolute", "top":"-100px"});

    document.getElementById('maingameframe').contentWindow.Event.prototype.preventDefault = () => {};

    window.addEventListener('load', () => {
        $('#bonkioheader')[0].style.visibility = "hidden";
//        $('#maingameframe').css({"position":"absolute", "top":"-100px"});

        let frame = document.getElementById('maingameframe');
        let frameDoc = document.getElementById('maingameframe').contentDocument;

        let a = 1;
        let setup;
        let observer = new MutationObserver((mutations, me) => {
            a += 1;
            if (frameDoc.getElementById('roomlisttopbar')) {
                me.disconnect(); // stop observing
                setup();
                return;
            }
        });
        observer.observe(frameDoc, {
            childList: true,
            subtree: true
        });

        setup = () => {
            window.$('#maingameframe').css({"position":"absolute", "top":"-100px"});

            let $ = frame.contentWindow.$;

            function filterRooms(s) {
                s = s.toLowerCase();
                let matches = el => el.children[0].textContent.toLowerCase().includes(s);
                $('#roomlisttable tr').each((i, el) => {
                    el.hidden = !matches(el);
                });
            }

            let inp = `<input type="text" id="roomSearchInputBox" placeholder="Search Rooms.." style="
                float: right;
                padding: 2px 8px;
                margin: 5px 20px;
                border: 2px solid #006157;
                border-radius: 5px;
                font: large futurept_b1;
                ">`;

            $('#roomlisttopbar').append(inp);

            $('#roomSearchInputBox').keyup(ev => filterRooms(ev.target.value));

            $('body').keydown( ev => {
                if (ev.altKey) {
                    if (ev.key === 'q' && $('#roomListContainer')[0].offsetParent === null) {
                        $('#pretty_top_exit').click(); $('#leaveconfirmwindow_okbutton').click();
                    }
                    else if (ev.key === 'r') {$('#roomlistrefreshbutton').click();}
                }
            });

    /****** Implemented by Chaz *******

            // Can double click room to trigger join
            let room_join_dblclick_handler = (ev) => $("#roomlistjoinbutton").click();
            $("#roomlisttable").on("dblclick", "tr", room_join_dblclick_handler);

            // Press enter to submit password for joining room
            let room_pass_enter_handler = (ev) => {
                ev.key === "Enter" && $("#roomlistpassjoinbutton").click();
            };
            $("#roomlistjoinpasswordtext").on("keydown", room_pass_enter_handler);
   *******/
        };
    });
})();