Double-click Instant Leave - Bonk.io

Leaves the lobby instantly when you double click the Leave button, bypassing the Confirm Window.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Double-click Instant Leave - Bonk.io
// @version      1.0.1
// @description  Leaves the lobby instantly when you double click the Leave button, bypassing the Confirm Window.
// @author       Miquella
// @namespace    https://greasyfork.org/en/users/1502869
// @license      GPL-3.0
// @match        https://bonk.io/gameframe-release.html
// @run-at       document-idle
// ==/UserScript==


(function () {
  // checks if the player is either in the lobby or in an active match
  const isPlayerInLobbyOrGame = () => {
    const lobbyElement = document.querySelector("#newbonklobby");
    const gameCanvas = document.querySelector("#gamerenderer canvas");
    const lobbyVisible = lobbyElement && getComputedStyle(lobbyElement).display !== "none";
    const gameVisible = gameCanvas &&
      getComputedStyle(gameCanvas).visibility !== "hidden" &&
      getComputedStyle(gameCanvas).opacity !== "0";
    return lobbyVisible || gameVisible;
  };
  // watches the dom for the leave button
  new MutationObserver(() => {
    const leaveBtn = document.querySelector("#pretty_top_exit");
    if (!leaveBtn || leaveBtn.dataset.instLeaveHooked) return;
    leaveBtn.dataset.instLeaveHooked = "true";
    // listens for double-click on the leave button
    leaveBtn.addEventListener("dblclick", e => {
      if (!isPlayerInLobbyOrGame()) return;
      e.preventDefault();
      e.stopPropagation();
      leaveBtn.click();
        const confirmBtn = document.querySelector("#leaveconfirmwindow_okbutton");
        if (confirmBtn) confirmBtn.click(); // instantly confirms leave
    });
  }).observe(document, { childList: true, subtree: true });
})();