Smashkarts Performance Enhancer

Improve overall game performance by disabling resource-heavy features and limiting frame rate.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Smashkarts Performance Enhancer
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Improve overall game performance by disabling resource-heavy features and limiting frame rate.
// @author       You
// @match        *://*.smashkarts.io/*
// @grant        none
// @run-at       document-end
// @license      All rights reserved  // <-- License added
// ==/UserScript==

(function() {
    'use strict';

    // Disable background music
    function disableBackgroundMusic() {
        let backgroundMusic = document.querySelector('audio');
        if (backgroundMusic) {
            backgroundMusic.muted = true; // Mutes the background music
        }
    }

    // Reduce or remove particle effects (if present)
    function disableParticles() {
        let particleSystems = document.querySelectorAll('.particle-system');
        particleSystems.forEach((system) => {
            system.style.display = "none"; // Hides particle systems for better performance
        });
    }

    // Lower the framerate for smoother performance (limit to 30 FPS)
    function limitFrameRate() {
        let originalRequestAnimationFrame = window.requestAnimationFrame;
        window.requestAnimationFrame = function(callback) {
            setTimeout(() => {
                originalRequestAnimationFrame(callback);
            }, 1000 / 30); // Throttles the frame rate to 30fps
        };
    }

    // Minimize DOM manipulation (show/hide instead of adding/removing elements)
    function optimizeDomManipulation() {
        let keyBoxes = document.querySelectorAll('.key-box');
        keyBoxes.forEach((box) => {
            box.style.transition = 'none'; // Disable transitions to improve performance
        });
    }

    // Optimize key event listeners (avoid constant DOM updates)
    function optimizeKeyEventListeners() {
        let lastPressedKey = null;

        document.addEventListener('keydown', function(event) {
            var key = event.key.toUpperCase();
            if (key === " ") key = "SPACE";
            if (key === "CONTROL") key = "CONTROL";

            if (key !== lastPressedKey) {
                // Change color or visibility based on key press, update DOM minimally
                updateKeyBoxColor(key, true);
                lastPressedKey = key;
            }
        });

        document.addEventListener('keyup', function(event) {
            var key = event.key.toUpperCase();
            if (key === " ") key = "SPACE";
            if (key === "CONTROL") key = "CONTROL";

            if (key === lastPressedKey) {
                updateKeyBoxColor(key, false);
                lastPressedKey = null;
            }
        });
    }

    // Update the color or visibility of keyboxes (minimized DOM update)
    function updateKeyBoxColor(key, isPressed) {
        let keyBoxes = document.querySelectorAll('.key-box');
        keyBoxes.forEach(function(box) {
            if (box.textContent === key) {
                if (isPressed) {
                    box.style.backgroundColor = box.dataset.color;  // Highlight key on press
                } else {
                    box.style.backgroundColor = 'transparent'; // Reset background on release
                }
            }
        });
    }

    // Initialize optimizations
    function initializeOptimizations() {
        disableBackgroundMusic();
        disableParticles();
        limitFrameRate();
        optimizeDomManipulation();
        optimizeKeyEventListeners();
    }

    // Initialize once the document is fully loaded
    window.addEventListener('load', function() {
        initializeOptimizations();
    });

})();