Bonk.io Anti Freeze

Prevents bonk.io from freezing

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name Bonk.io Anti Freeze
// @version      0.1
// @description  Prevents bonk.io from freezing
// @author       UrsoTriangular
// @match        https://bonk.io/gameframe-release.html
// @run-at       document-start
// @grant        none
// @namespace https://greasyfork.org/users/984927
// ==/UserScript==

const maximumTimeInsideLoop = 40;

function inject(code) {
    // Variable name followed by [index]
    const VAR = '[$A-Za-z][\\w$_]{1,5}\\[\\d+\\]';

    let replaced = false;

    // The loop we need to match is luckily the first one in the code, this migth change in a future update
    code = code.replace(new RegExp(`(${VAR});${VAR}=30;while\\(${VAR} > 1000 \/ ${VAR}\\)\\{`), function(whole, lastTime) {
        replaced = true;
        return `${whole}if (Date.now() - ${lastTime} > ${maximumTimeInsideLoop}) break;`;
    });

    if (!replaced) {
        throw new Error("Repĺace failed");
    }

    return code;
}



if (!window.bonkCodeInjectors) window.bonkCodeInjectors = [];

window.bonkCodeInjectors.push(function AntiFreeze(code) {
    try {
        code = inject(code);
        console.log("[Anti Freeze] Injector run");
    }
    catch (e) {
        console.error("[Anti Freeze] Injector error:", e);
    }

    return code;
});