您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Accelerate video loading by lazy loading videos
当前为
// ==UserScript== // @name Lazy Load Videos // @namespace http://tampermonkey.net/ // @version 1.1 // @description Accelerate video loading by lazy loading videos // @author tae // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // Function to lazy load videos function lazyLoadVideos() { const videos = document.querySelectorAll('video'); const config = { rootMargin: '0px 0px 50px 0px', threshold: 0.01 }; let observer; if ('IntersectionObserver' in window) { observer = new IntersectionObserver((entries, self) => { entries.forEach(entry => { if (entry.isIntersecting) { let video = entry.target; video.src = video.dataset.src; video.load(); video.pause(); // Ensure the video is paused before loading self.unobserve(video); } }); }, config); videos.forEach(video => { if (video.dataset.src) { observer.observe(video); } }); } else { // Fallback for browsers that don't support IntersectionObserver videos.forEach(video => { if (video.dataset.src) { video.src = video.dataset.src; video.load(); video.pause(); // Ensure the video is paused before loading } }); } } // Run the lazy load function on page load window.addEventListener('load', lazyLoadVideos); })();