// 示例:Chrome扩展核心代码 function injectDownloadButton() { // 监听视频元素加载 const observer = new MutationObserver(mutations => { mutations.forEach(mutation => { if (mutation.addedNodes.length) { // 查找视频元素 const videoElements = document.querySelectorAll('video'); videoElements.forEach(video => { if (!video.dataset.downloadAdded) { video.dataset.downloadAdded = true; // 创建下载按钮 const downloadBtn = document.createElement('button'); downloadBtn.textContent = '下载视频'; downloadBtn.onclick = () => { const blobUrl = URL.createObjectURL(video.src); const a = document.createElement('a'); a.href = blobUrl; a.download = `video_${Date.now()}.mp4`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(blobUrl); }; // 将按钮添加到视频附近 video.parentNode.insertBefore(downloadBtn, video.nextSibling); } }); } }); }); // 开始观察DOM变化 observer.observe(document.body, { childList: true, subtree: true }); } // 注入到视频号页面 injectDownloadButton();