Quicklink Smart Prefetch

Quicklink with browser-specific options + network-aware + ignores for login/logout/account links

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Quicklink Smart Prefetch
// @namespace    https://www.tampermonkey.net/
// @version      1.9
// @description  Quicklink with browser-specific options + network-aware + ignores for login/logout/account links
// @author       Chatgpt
// @match        *://*/*
// @grant        none
// @require      https://unpkg.com/[email protected]/dist/quicklink.umd.js
// ==/UserScript==

(function() {
    'use strict';

    try {
        const ua = navigator.userAgent.toLowerCase();
        const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;

        // Skip Quicklink on very slow (2G) connections or Save-Data mode
        if (connection) {
            if (connection.saveData) {
                console.warn("Quicklink disabled: Save-Data mode is ON");
                return;
            }
            if (connection.effectiveType && /2g/.test(connection.effectiveType)) {
                console.warn("Quicklink disabled: Connection is too slow (" + connection.effectiveType + ")");
                return;
            }
        }

        // Quicklink options & thank you Shannon Turner for the code for the logout,login,etc
        const options = {
            origins: true,
            ignores: [
                /\/api\/?/,
                uri => uri.includes('.zip'),
                (uri, elem) => elem.hasAttribute('noprefetch'),
                uri => uri.includes('logout'),
                uri => uri.includes('login'),
                uri => uri.includes('account')
            ],
            onError: (err, url, el) => {
                console.error("Quicklink error:", {err, url, el});
            }
        };

        if (ua.includes("chrome") || ua.includes("edg")) {
            options.prerenderAndPrefetch = true;
        } else if (ua.includes("firefox") || ua.includes("safari")) {
            options.prerenderAndPrefetch = false;
        }

        // Initialize Quicklink
        quicklink.listen(options);

        console.log("Quicklink initialized with options:", options, "connection:", connection || "n/a");
    } catch (e) {
        console.error("Quicklink failed to initialize:", e);
    }
})();