Double-click Ready to Start - Bonk.io

Starts the game without a countdown if you doubleclick the Ready button.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Double-click Ready to Start - Bonk.io
// @version      1.0.0
// @description  Starts the game without a countdown if you doubleclick the Ready button.
// @author       Excigma
// @namespace    https://greasyfork.org/users/416480
// @license      GPL-3.0
// @match        https://bonk.io/gameframe-release.html
// @run-at       document-idle
// ==/UserScript==

(() => {
	// Whether Ready was double clicked
	let quickStart = false;

	// Main canvas where the game is drawn on
	const gamerenderer = document.getElementById("gamerenderer");
	// Test button that starts the game right away from the map editor
	const mapeditor_midbox_testbutton = document.getElementById("mapeditor_midbox_testbutton");
	// Close map editor
	const mapeditor_close = document.getElementById("mapeditor_close");
	// Button to open map editor
	const newbonklobby_editorbutton = document.getElementById("newbonklobby_editorbutton");
	// Ready button
	const newbonklobby_readybutton = document.getElementById("newbonklobby_readybutton");
	// Start button
	const newbonklobby_startbutton = document.getElementById("newbonklobby_startbutton");

	// Detect double click
	newbonklobby_readybutton.addEventListener("dblclick", () => {
		if (!newbonklobby_startbutton.classList.contains("brownButtonDisabled")) {
			quickStart = true;
			// Open the editor
			newbonklobby_editorbutton.click();
			// Start the game using the button from the editor
			mapeditor_midbox_testbutton.click();
		}
	});

	new MutationObserver(mutationsList => {
		for (const mutation of mutationsList) {
			// The "gamerenderer" has been hidden (this is used to render the match and stuffs)
			// In short, this means we have left the game or returned to the lobby
			if (gamerenderer.style.visibility === "hidden") {
				// If quick start was used, then close the map editor
				// because the map editor will open after the round ends
				if (quickStart) {
					mapeditor_close.click();
					quickStart = false;
				}
			}
		}
	}).observe(gamerenderer, {
		attributeFilter: ["style"]
	});
})();