Speed Up Web Page Loading

Make web pages load faster by blocking ads and implementing lazy loading for images.

Από την 16/06/2024. Δείτε την τελευταία έκδοση.

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Speed Up Web Page Loading
// @namespace    https://discord.gg/gFNAH7WNZj
// @version      1.2
// @description  Make web pages load faster by blocking ads and implementing lazy loading for images.
// @author       Bacon But Pro
// @match        *://*/*
// @grant        none
// @icon         https://cdn141.picsart.com/351217840073211.png
// @license MIT
// ==/UserScript==
 
(function() {
    'use strict';
 
    // Block ads and tracking scripts
    const blockedDomains = [
        'doubleclick.net',
        'googlesyndication.com',
        'google-analytics.com',
        'adsafeprotected.com',
        'adnxs.com',
        'rubiconproject.com',
        'pubmatic.com',
        'scorecardresearch.com',
        'bluekai.com',
        'facebook.net',
        'twitter.com',
        'amazon-adsystem.com',
        'ads-twitter.com',
        'criteo.com',
        'taboola.com',
        'outbrain.com',
        'cdn.ampproject.org',
        'quantserve.com',
        'googletagmanager.com',
        'yahoo.com',
        'gemini.yahoo.com'
    ];
 
    const observer = new MutationObserver(() => {
        document.querySelectorAll('script[src], iframe[src]').forEach(el => {
            blockedDomains.forEach(domain => {
                if (el.src.includes(domain)) {
                    el.remove();
                }
            });
        });
    });
 
    observer.observe(document.documentElement, { childList: true, subtree: true });
 
    // Implement lazy loading for images
    document.addEventListener('DOMContentLoaded', () => {
        const images = document.querySelectorAll('img');
 
        images.forEach(image => {
            if (image.complete) return;
            image.setAttribute('loading', 'lazy');
        });
 
        const lazyLoadObserver = new IntersectionObserver((entries, observer) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    const img = entry.target;
                    img.src = img.dataset.src;
                    observer.unobserve(img);
                }
            });
        });
 
        images.forEach(img => {
            if (img.dataset.src) {
                lazyLoadObserver.observe(img);
            } else {
                img.dataset.src = img.src;
                img.src = '';
                lazyLoadObserver.observe(img);
            }
        });
    });

    // Remove unwanted elements like pop-ups
    const removeUnwantedElements = () => {
        const unwantedSelectors = [
            '.popup', // common class name for pop-ups
            '.ad-banner', // common class name for ad banners
            '#subscribe-modal', // common ID for subscription modals
            '.overlay', // common class name for overlay ads
        ];

        unwantedSelectors.forEach(selector => {
            document.querySelectorAll(selector).forEach(el => el.remove());
        });
    };

    const unwantedObserver = new MutationObserver(removeUnwantedElements);
    unwantedObserver.observe(document.documentElement, { childList: true, subtree: true });
    document.addEventListener('DOMContentLoaded', removeUnwantedElements);
})();