您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Make web pages load faster by blocking ads and implementing lazy loading for images.
当前为
- // ==UserScript==
- // @name Speed Up Web Page Loading
- // @namespace https://discord.gg/gFNAH7WNZj
- // @version 1.0
- // @description Make web pages load faster by blocking ads and implementing lazy loading for images.
- // @author Bacon But Pro
- // @match *://*/*
- // @grant none
- // @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'
- ];
- 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);
- }
- });
- });
- })();