Chromebook Game Performance Booster

Reduces lag and boosts FPS to 60-120 for gaming on Chromebooks

Size

10.5 KB

Version

1.0.1

Created

Jan 20, 2026

Updated

26 days ago

1// ==UserScript==
2// @name		Chromebook Game Performance Booster
3// @description		Reduces lag and boosts FPS to 60-120 for gaming on Chromebooks
4// @version		1.0.1
5// @match		*://*/*
6// @icon		https://robomonkey.io/favicon.ico
7// @grant		GM.getValue
8// @grant		GM.setValue
9// ==/UserScript==
10(function() {
11    'use strict';
12
13    console.log('Chromebook Game Performance Booster - Starting optimization...');
14
15    // Performance optimization settings
16    const performanceConfig = {
17        targetFPS: 60,
18        maxFPS: 120,
19        enableOptimizations: true
20    };
21
22    // Debounce function to prevent excessive calls
23    function debounce(func, wait) {
24        let timeout;
25        return function executedFunction(...args) {
26            const later = () => {
27                clearTimeout(timeout);
28                func(...args);
29            };
30            clearTimeout(timeout);
31            timeout = setTimeout(later, wait);
32        };
33    }
34
35    // Initialize performance optimizations
36    async function init() {
37        console.log('Initializing performance optimizations...');
38
39        // Load saved settings
40        const savedSettings = await GM.getValue('performanceSettings', null);
41        if (savedSettings) {
42            Object.assign(performanceConfig, JSON.parse(savedSettings));
43        }
44
45        // Apply all optimizations
46        optimizeCanvas();
47        optimizeWebGL();
48        optimizeAnimations();
49        optimizeMemory();
50        optimizeNetworking();
51        disableUnnecessaryFeatures();
52        createPerformanceMonitor();
53        
54        console.log('Performance optimizations applied successfully!');
55    }
56
57    // Optimize Canvas rendering
58    function optimizeCanvas() {
59        const originalGetContext = HTMLCanvasElement.prototype.getContext;
60        HTMLCanvasElement.prototype.getContext = function(type, attributes = {}) {
61            if (type === '2d') {
62                // Optimize 2D context
63                attributes.alpha = attributes.alpha !== undefined ? attributes.alpha : false;
64                attributes.desynchronized = true;
65                attributes.willReadFrequently = false;
66            } else if (type === 'webgl' || type === 'webgl2') {
67                // Optimize WebGL context
68                attributes.alpha = attributes.alpha !== undefined ? attributes.alpha : false;
69                attributes.antialias = attributes.antialias !== undefined ? attributes.antialias : false;
70                attributes.depth = attributes.depth !== undefined ? attributes.depth : true;
71                attributes.desynchronized = true;
72                attributes.powerPreference = 'high-performance';
73                attributes.failIfMajorPerformanceCaveat = false;
74            }
75            return originalGetContext.call(this, type, attributes);
76        };
77        console.log('Canvas optimization applied');
78    }
79
80    // Optimize WebGL settings
81    function optimizeWebGL() {
82        if (window.WebGLRenderingContext) {
83            const originalGetParameter = WebGLRenderingContext.prototype.getParameter;
84            WebGLRenderingContext.prototype.getParameter = function(pname) {
85                // Force high performance settings
86                if (pname === this.MAX_TEXTURE_SIZE) {
87                    return Math.min(originalGetParameter.call(this, pname), 4096);
88                }
89                return originalGetParameter.call(this, pname);
90            };
91        }
92        console.log('WebGL optimization applied');
93    }
94
95    // Optimize animations and frame rate
96    function optimizeAnimations() {
97        let lastFrameTime = performance.now();
98        let frameCount = 0;
99        const targetFrameTime = 1000 / performanceConfig.maxFPS;
100
101        // Override requestAnimationFrame for FPS limiting
102        const originalRAF = window.requestAnimationFrame;
103        window.requestAnimationFrame = function(callback) {
104            return originalRAF.call(window, function(timestamp) {
105                const elapsed = timestamp - lastFrameTime;
106                
107                if (elapsed >= targetFrameTime) {
108                    lastFrameTime = timestamp - (elapsed % targetFrameTime);
109                    frameCount++;
110                    callback(timestamp);
111                }
112            });
113        };
114
115        // Disable CSS animations on non-game elements to save resources
116        const style = document.createElement('style');
117        style.textContent = `
118            * {
119                -webkit-font-smoothing: antialiased;
120                -moz-osx-font-smoothing: grayscale;
121            }
122            body *:not(canvas):not(#game-container):not([class*="game"]):not([id*="game"]) {
123                animation-duration: 0.01ms !important;
124                animation-iteration-count: 1 !important;
125                transition-duration: 0.01ms !important;
126            }
127        `;
128        document.head.appendChild(style);
129        
130        console.log('Animation optimization applied');
131    }
132
133    // Optimize memory usage
134    function optimizeMemory() {
135        // Aggressive garbage collection hints
136        setInterval(() => {
137            if (window.gc) {
138                window.gc();
139            }
140        }, 30000);
141
142        // Clear unused resources
143        const observer = new MutationObserver(debounce(() => {
144            // Remove hidden images to free memory
145            document.querySelectorAll('img[style*="display: none"], img[style*="visibility: hidden"]').forEach(img => {
146                if (!img.closest('canvas')) {
147                    img.src = '';
148                }
149            });
150        }, 2000));
151
152        observer.observe(document.body, {
153            childList: true,
154            subtree: true
155        });
156
157        console.log('Memory optimization applied');
158    }
159
160    // Optimize networking for games
161    function optimizeNetworking() {
162        // Prioritize game-related network requests
163        if (window.fetch) {
164            const originalFetch = window.fetch;
165            window.fetch = function(url, options = {}) {
166                // Add high priority to game assets
167                if (typeof url === 'string' && 
168                    (url.includes('game') || url.includes('asset') || url.includes('api'))) {
169                    options.priority = 'high';
170                }
171                return originalFetch.call(window, url, options);
172            };
173        }
174        console.log('Network optimization applied');
175    }
176
177    // Disable unnecessary features
178    function disableUnnecessaryFeatures() {
179        // Disable smooth scrolling for better performance
180        document.documentElement.style.scrollBehavior = 'auto';
181
182        // Reduce image quality for non-game images
183        const style = document.createElement('style');
184        style.textContent = `
185            img:not([src*="game"]):not([class*="game"]) {
186                image-rendering: -webkit-optimize-contrast;
187                image-rendering: crisp-edges;
188            }
189            video:not([class*="game"]) {
190                transform: translateZ(0);
191            }
192        `;
193        document.head.appendChild(style);
194
195        // Disable unnecessary browser features
196        try {
197            if ('serviceWorker' in navigator) {
198                navigator.serviceWorker.getRegistrations().then(registrations => {
199                    registrations.forEach(registration => {
200                        // Keep only game-related service workers
201                        if (!registration.scope.includes('game')) {
202                            registration.unregister();
203                        }
204                    });
205                });
206            }
207        } catch (e) {
208            console.log('Service worker optimization skipped');
209        }
210
211        console.log('Unnecessary features disabled');
212    }
213
214    // Create performance monitor overlay
215    function createPerformanceMonitor() {
216        const monitor = document.createElement('div');
217        monitor.id = 'performance-monitor';
218        monitor.style.cssText = `
219            position: fixed;
220            top: 10px;
221            right: 10px;
222            background: rgba(0, 0, 0, 0.8);
223            color: #00ff00;
224            padding: 10px;
225            border-radius: 5px;
226            font-family: monospace;
227            font-size: 12px;
228            z-index: 999999;
229            min-width: 150px;
230            pointer-events: none;
231            user-select: none;
232        `;
233
234        const fpsDisplay = document.createElement('div');
235        fpsDisplay.textContent = 'FPS: --';
236        monitor.appendChild(fpsDisplay);
237
238        const memoryDisplay = document.createElement('div');
239        memoryDisplay.textContent = 'Memory: --';
240        monitor.appendChild(memoryDisplay);
241
242        const statusDisplay = document.createElement('div');
243        statusDisplay.textContent = '🚀 Optimized';
244        statusDisplay.style.color = '#00ff00';
245        monitor.appendChild(statusDisplay);
246
247        document.body.appendChild(monitor);
248
249        // FPS counter
250        let frames = 0;
251        let lastTime = performance.now();
252
253        function updateFPS() {
254            frames++;
255            const currentTime = performance.now();
256            
257            if (currentTime >= lastTime + 1000) {
258                const fps = Math.round((frames * 1000) / (currentTime - lastTime));
259                fpsDisplay.textContent = `FPS: ${fps}`;
260                
261                // Color code based on performance
262                if (fps >= 60) {
263                    fpsDisplay.style.color = '#00ff00';
264                } else if (fps >= 30) {
265                    fpsDisplay.style.color = '#ffff00';
266                } else {
267                    fpsDisplay.style.color = '#ff0000';
268                }
269                
270                frames = 0;
271                lastTime = currentTime;
272            }
273            
274            requestAnimationFrame(updateFPS);
275        }
276        updateFPS();
277
278        // Memory usage
279        if (performance.memory) {
280            setInterval(() => {
281                const usedMemory = (performance.memory.usedJSHeapSize / 1048576).toFixed(1);
282                const totalMemory = (performance.memory.totalJSHeapSize / 1048576).toFixed(1);
283                memoryDisplay.textContent = `Memory: ${usedMemory}/${totalMemory} MB`;
284            }, 2000);
285        }
286
287        console.log('Performance monitor created');
288    }
289
290    // Wait for page to be ready
291    if (document.body) {
292        init();
293    } else {
294        const observer = new MutationObserver(() => {
295            if (document.body) {
296                observer.disconnect();
297                init();
298            }
299        });
300        observer.observe(document.documentElement, { childList: true });
301    }
302
303})();
Chromebook Game Performance Booster | Robomonkey