Double-click Instant Leave - Bonk.io

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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 });
})();