Super Fast Loading

Boost website loading speed and video playback while preventing autoplay. This script enhances loading times for images and videos, making it ideal for users with limited internet access. Although it can't increase your internet speed, it ensures a smoother browsing experience. Try this code for improved speed!

目前為 2024-11-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Super Fast Loading
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Boost website loading speed and video playback while preventing autoplay. This script enhances loading times for images and videos, making it ideal for users with limited internet access. Although it can't increase your internet speed, it ensures a smoother browsing experience. Try this code for improved speed!
// @author       Farzan Farhangi
// @match        *://*/*
// @grant        GM_xmlhttpRequest
// @grant        GM_setValue
// @grant        GM_getValue
// @homepage     https://greasyfork.org/en/scripts/517138-super-fast-loading
// ==/UserScript==

(function() {
    'use strict';

    const cacheKeyPrefix = 'cachedResource_';
    const simulatedSpeedFactor = 1; // Simulate actual speed for better performance

    // Load cached resources
    const loadCachedResource = (url) => {
        const cachedData = GM_getValue(cacheKeyPrefix + url);
        if (cachedData) {
            const script = document.createElement('script');
            script.textContent = cachedData;
            document.head.appendChild(script);
            return true;
        }
        return false;
    };

    // Fetch and cache resources with simulated delay
    const fetchAndCacheResource = async (url) => {
        try {
            await new Promise(resolve => setTimeout(resolve, 1000 / simulatedSpeedFactor)); // Simulate network delay
            const response = await new Promise((resolve, reject) => {
                GM_xmlhttpRequest({
                    method: "GET",
                    url: url,
                    onload: resolve,
                    onerror: reject
                });
            });
            if (response.status === 200) {
                GM_setValue(cacheKeyPrefix + url, response.responseText);
                const script = document.createElement('script');
                script.textContent = response.responseText;
                document.head.appendChild(script);
            }
        } catch (error) {
            console.error(`Failed to fetch resource: ${url}`, error);
        }
    };

    // Preload critical resources for faster initial load
    const preloadCriticalResources = () => {
        const criticalResources = [
            '/index.html',
            '/styles.css',
            '/script.js',
            // Add other critical resources as needed
        ];

        criticalResources.forEach(url => {
            fetchAndCacheResource(url);
        });
    };

    // Optimize initial loading by fetching resources in parallel
    const optimizeInitialLoad = () => {
        const initialResources = [
            '/index.html',
            '/styles.css',
            '/script.js',
            // Add any other resources that should be loaded initially
        ];

        initialResources.forEach(url => {
            fetchAndCacheResource(url); // Fetch each resource simultaneously for faster loading
        });
    };

    preloadCriticalResources();
    optimizeInitialLoad();
})();