工具 影音

工具

谷歌浏览器网页M3U8视频链接插件v1.1

更新时间: 2025-11-08      阅读 收藏
立即下载

谷歌浏览器网页M3U8视频链接插件v1.1(图1)


功能介绍
简单快速提取当前页面或全部页面的M3U8链接
支持显示抓取结果,格式为:标题,链接
支持复制所有结果,格式为:标题,链接,可用于m3u8批量下载软件的模板

关键代码:

  1.     // 抓取当前页面M3U8链接
  2.     currentPageBtn.addEventListener('click', async () => {
  3.         setStatus('正在抓取当前页面链接...', true);
  4.  
  5.         try {
  6.             // 获取当前活动标签页
  7.             const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
  8.  
  9.             // 注入内容脚本并执行抓取
  10.             const results = await chrome.scripting.executeScript({
  11.                 target: { tabId: tab.id },
  12.                 function: findM3U8Links
  13.             });
  14.  
  15.                         // 结果 显示时去重
  16.                         const m3u8Links = results[0].result;
  17.                         ...
  18.  
  19. // 在页面中查找M3U8链接的函数
  20. function findM3U8Links() {
  21.     const m3u8Links = new Set();
  22.  
  23.     // 查找所有可能的M3U8链接来源
  24.     const sources = [
  25.         // 1. 查找<script>标签中的M3U8链接
  26.         ...Array.from(document.scripts).map(script => script.innerHTML),
  27.  
  28.         // 2. 查找JSON数据
  29.         ...Array.from(document.querySelectorAll('*')).map(el => el.innerHTML),
  30.  
  31.         // 3. 查找视频标签
  32.         ...Array.from(document.querySelectorAll('video source')).map(source => source.src),
  33.  
  34.         // 4. 查找所有链接
  35.         ...Array.from(document.querySelectorAll('a')).map(a => a.href)
  36.     ];
  37.  
  38.     // M3U8链接正则表达式
  39.     const m3u8Regex = /https?:\/\/[^\s"']+\.m3u8(?:\?[^\s"']*)?/gi;
  40.  
  41.     // 在所有来源中搜索M3U8链接
  42.     sources.forEach(source => {
  43.         if (typeof source === 'string') {
  44.             const matches = source.match(m3u8Regex);
  45.             if (matches) {
  46.                 matches.forEach(match => m3u8Links.add(match));
  47.             }
  48.         }
  49.     });
  50.         ...
复制代码


- THE END -
取消
微信二维码
微信二维码
支付宝二维码
最新推荐
推荐标签