Hardware Acceleration and Web Performance Enhancer

Toggle hardware acceleration and enhance web performance without logging users out

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Hardware Acceleration and Web Performance Enhancer
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Toggle hardware acceleration and enhance web performance without logging users out
// @author       Tae
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Load Quicklink library to enhance link prefetching
    const script = document.createElement('script');
    script.src = 'https://unpkg.com/[email protected]/dist/quicklink.umd.js';
    script.onload = () => {
        if (typeof quicklink !== 'undefined') {
            try {
                quicklink.listen({
                    origins: true,
                    ignores: [
                        (uri) => uri.includes('logout'),
                        (uri) => uri.includes('login'),
                        (uri) => uri.includes('account')
                    ]
                });
            } catch (error) {
                console.error('Error initializing Quicklink:', error);
            }
        } else {
            console.error('Quicklink library is not available.');
        }
    };
    script.onerror = () => {
        console.error('Error loading Quicklink library.');
    };
    document.head.appendChild(script);

    // Global error listener
    window.addEventListener('error', (event) => {
        console.error('Script error:', event.message, 'at', event.filename, 'line', event.lineno);
    });

    // Prevent navigation to logout, login, or account pages on link clicks
    document.addEventListener('click', (event) => {
        const target = event.target.closest('a[href]');
        if (target && (target.href.includes('logout') || target.href.includes('login') || target.href.includes('account'))) {
            event.preventDefault();
            console.warn('Prevented navigation to:', target.href);
        }
    });

    // Prevent 503 errors by sending keep-alive requests
    const sendKeepAlive = () => {
        const url = '/keep-alive';
        if (navigator.sendBeacon) {
            try {
                navigator.sendBeacon(url, '');
            } catch (error) {
                console.error('Error sending beacon:', error);
            }
        } else {
            const xhr = new XMLHttpRequest();
            xhr.open('POST', url, true);
            xhr.onerror = () => {
                console.error('Error with keep-alive request:', xhr.statusText);
            };
            xhr.send('');
        }
    };
    setInterval(sendKeepAlive, 300000); // Send keep-alive request every 5 minutes

})();