Starblast lag/ping reducer

12/5/2024, 3:35:19 PM

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name        Starblast lag/ping reducer
// @namespace   Violentmonkey Scripts
// @match       https://starblast.io/
// @grant       none
// @version     1.0
// @author      -
// @description 12/5/2024, 3:35:19 PM
// ==/UserScript==
// ==UserScript==
// @name         Preformance optimizer
// @version      0.2
// @description  Allows different for lower ping and better game preformance
// @author       WOB
// @match        https://starblast.io/
// @run-at       document-end
// @grant        none

(function() {
    // Ensure the script runs only once
    if (window.performanceOptimized) return;
    window.performanceOptimized = true;

    // 1. Optimize canvas settings for smoother rendering without breaking visuals
    const canvas = document.getElementsByTagName('canvas')[0];
    if (canvas) {
        const context = canvas.getContext('2d');
        if (context) {
            // Disable image smoothing for performance without affecting visuals
            context.imageSmoothingEnabled = false;
            context.msImageSmoothingEnabled = false;
            console.log("Canvas image smoothing disabled for performance.");
        }
    } else {
        console.log("Canvas not found.");
    }

    // 2. Disable unnecessary animations that might cause lag (setInterval and requestAnimationFrame)
    window.requestAnimationFrame = function(callback) {
        setTimeout(callback, 16);  // Force a 60 FPS rate (16 ms per frame)
    };

    // 3. Limit the frequency of DOM manipulations (throttle updates)
    let lastDOMUpdate = Date.now();
    const throttleDOMUpdates = () => {
        const currentTime = Date.now();
        if (currentTime - lastDOMUpdate > 50) { // Throttle to 20 FPS
            lastDOMUpdate = currentTime;
            // Add logic for DOM manipulation updates if needed
        }
    };
    setInterval(throttleDOMUpdates, 50); // Throttle DOM updates every 50ms

    // 4. Disable sound to reduce CPU/GPU load (optional)
    const audio = document.querySelectorAll('audio');
    audio.forEach(a => a.muted = true);
    console.log("Audio muted to reduce CPU/GPU load.");

    // 5. Remove unnecessary DOM elements that may consume resources
    const removeUnnecessaryElements = () => {
        const elements = document.querySelectorAll('.unnecessary-class');
        elements.forEach(element => element.remove());
    };
    setInterval(removeUnnecessaryElements, 1000); // Remove every second

    // 6. Prevent excessive memory use by clearing unnecessary intervals
    const clearUnnecessaryIntervals = () => {
        const currentTime = Date.now();
        if (currentTime - lastTime > 10000) {
            clearInterval(clearUnnecessaryIntervals);
            console.log("Removed unnecessary intervals.");
        }
    };
    setInterval(clearUnnecessaryIntervals, 1000);

    // 7. Optionally reduce high GPU/CSS rendering styles
    const removeHeavyCSS = () => {
        const styleSheets = document.styleSheets;
        for (let i = 0; i < styleSheets.length; i++) {
            const rules = styleSheets[i].cssRules;
            if (rules) {
                for (let j = 0; j < rules.length; j++) {
                    const rule = rules[j];
                    if (rule && rule.style) {
                        const style = rule.style;
                        // Disable box-shadows and other potentially performance-heavy effects
                        if (style.boxShadow) {
                            style.boxShadow = 'none';
                        }
                    }
                }
            }
        }
    };
    setInterval(removeHeavyCSS, 2000); // Check every 2 seconds

    // 8. Prevent right-click context menu (optional)
    window.addEventListener('contextmenu', (e) => e.preventDefault());

    // 9. Log the success of optimizations
    console.log("Performance optimizations applied successfully.");
})();