// ==UserScript== // @name TMall Video URL Sniffer // @namespace https://scriptcat.org/zh-CN/users/161051 // @version 1.0 // @description 拦截天猫视频的真实 URL(支持 XHR/fetch/video.src) // @author MYZ // @match https://detail.tmall.com/* // @grant unsafeWindow // @grant GM_download // @run-at document-start // ==/UserScript== (function() { 'use strict'; // 存储已发现的视频 URL,避免重复添加按钮 const foundUrls = new Set(); // 1. 拦截 XMLHttpRequest const originalXHR = unsafeWindow.XMLHttpRequest; unsafeWindow.XMLHttpRequest = function() { const xhr = new originalXHR(); const originalOpen = xhr.open; xhr.open = function(method, url) { if (isVideoUrl(url)) { console.log('[XHR] ======================= 发现视频 URL:', url); handleVideoUrl(url); } originalOpen.apply(this, arguments); }; return xhr; }; // 2. 拦截 fetch 请求 const originalFetch = unsafeWindow.fetch; unsafeWindow.fetch = function(input, init) { const url = typeof input === 'string' ? input : input.url; if (isVideoUrl(url)) { console.log('[Fetch] ======================= 发现视频 URL:', url); handleVideoUrl(url); } return originalFetch.apply(this, arguments); }; // 3. 监听