返回首頁 

Greasy Fork is available in English.

YouTube to YouTube No-Cookie Embed Player

RedirectYouTube video URLs to the no-cookie embed player and stop all requests from loading


安装此脚本?
// ==UserScript==// @name         YouTube to YouTube No-Cookie Embed Player// @namespace    https://gist.github.com/thedoggybrad/4e17b0046ce072afc3f31610dcdef32a// @version      0.0.3// @description  RedirectYouTube video URLs to the no-cookie embed player and stop all requests from loading// @author       TheDoggyBrad Software Labs// @match        https://www.youtube.com/*// @grant        none// @license      MIT--0// @run-at       document-start// ==/UserScript==(function() {'use strict';// Function to block all network requestsfunction blockNetworkRequests() {// Intercept fetch APIconst originalFetch = window.fetch;window.fetch = function() {return new Promise((resolve, reject) => {// Reject all network requests made to YouTube domainsif (arguments[0].includes('youtube.com') || arguments[0].includes('google.com')) {reject('Blocked YouTube Request');} else {resolve(originalFetch.apply(this, arguments));}});};// Intercept XMLHttpRequestconst originalXHR = window.XMLHttpRequest;window.XMLHttpRequest = function() {const xhr = new originalXHR();const originalOpen = xhr.open;xhr.open = function(method, url) {if (url.includes('youtube.com') || url.includes('google.com')) {console.log('Blocked YouTube Request');xhr.abort();} else {originalOpen.apply(this, arguments);}};return xhr;};}// Function to redirect to no-cookie embedfunction redirectToEmbed() {let currentUrl = window.location.href;// Check if the current URL is a YouTube video pagelet match = currentUrl.match(/https:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_-]+)/);if (match) {let videoId = match[1];let embedUrl = `https://www.youtube-nocookie.com/embed/${videoId}`;// Redirect immediately without letting the original page loadif (window.location.href !== embedUrl) {window.location.replace(embedUrl); // Prevent page load by redirecting}}}// Run the redirection as early as possible (before any content loads)redirectToEmbed();// Block all network requests (scripts, images, etc.) to YouTube and Google domainsblockNetworkRequests();})();