Greasy Fork

文武直链助手-百度网盘在线解析网页直链获取助手

不限制速度的百度网盘SVIP解析直链网页获取助手,支持 Gopeed(一键解析)、IDM、NDM 等多线程极速下载工具

当前为 2025-01-06 提交的版本,查看 最新版本

// ==UserScript==
// @name         文武直链助手-百度网盘在线解析网页直链获取助手
// @namespace    https://github.com/dongyubin/Baidu-VIP
// @version      0.3
// @description  不限制速度的百度网盘SVIP解析直链网页获取助手,支持 Gopeed(一键解析)、IDM、NDM 等多线程极速下载工具
// @author       DongYubin
// @homepage     https://fk.wwkejishe.top/buy/23
// @supportURL   https://fk.wwkejishe.top/buy/23
// @license      MIT
// @match        https://pandown.mlover.site/*
// @icon         https://fk.wwkejishe.top/uploads/images/6e798005b00ce678782af4e6931f4374.png
// @resource     layuiCSS https://cdnjs.cloudflare.com/ajax/libs/layui/2.9.20/css/layui.min.css
// @require      https://cdnjs.cloudflare.com/ajax/libs/layui/2.9.20/layui.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js
// @grant        GM_cookie
// @grant        GM_addStyle
// @grant        GM_getResourceText
// @grant        GM_setClipboard
// ==/UserScript==
const layuiCss = GM_getResourceText('layuiCSS');
GM_addStyle(layuiCss);
function addXMLRequestCallback(callback) {
  var oldSend, i;
  if (XMLHttpRequest.callbacks) {
    // we've already overridden send() so just add the callback
    XMLHttpRequest.callbacks.push(callback);
  } else {
    // create a callback queue
    XMLHttpRequest.callbacks = [callback];
    // store the native send()
    oldSend = XMLHttpRequest.prototype.send;
    // override the native send()
    XMLHttpRequest.prototype.send = function () {
      // process the callback queue
      for (i = 0; i < XMLHttpRequest.callbacks.length; i++) {
        XMLHttpRequest.callbacks[i](this);
      }
      // call the native send()
      oldSend.apply(this, arguments);
    }
  }
}

// e.g.
addXMLRequestCallback(function (xhr) {
  xhr.addEventListener("load", function () {
    if (xhr.readyState == 4 && xhr.status == 200) {
      const url = xhr.responseURL;
      // console.log('拦截返回:', xhr);
      if (url.includes('https://api.aifenxiang.net.cn/wp/fast/pc/dlink') || url.includes('https://api.aifenxiang.net.cn/wp/dlink')) {
        try {
          const responseData = JSON.parse(xhr.responseText);
          const downloadUrl = responseData.data.data.dlink;
          const ua = responseData.data.data.ua;
          layer.open({
            content: `未下载成功,先设置IDM/NDM User-Agent:<code>` + ua + `</code>,再复制直链下载!`,
            btn: ['已下载,关闭弹窗', '复制UA', '未下载,复制直链'],
            closeBtn: 0,
            type: 1,
            btn1: function (index, layero, that) {
              layer.close(index);
            },
            btn2: function (index, layero, that) {
              GM_setClipboard(ua, "text");
              layer.msg('UA复制成功!');
              return false;
            },
            btn3: function (index, layero, that) {
              GM_setClipboard(downloadUrl, "text");
              layer.msg(`直链复制成功!`);
              layer.close(index);
            }
          });
          // alert('下载链接: ' + downloadUrl);
        } catch (e) {
          console.error('解析响应时出错: ', e);
        }
      }

      // else if (url.includes('https://api.aifenxiang.net.cn/wp/dlink')) {
      //   try {
      //     const responseData = JSON.parse(xhr.responseText);
      //     const downloadUrl = responseData.data.data.dlink;
      //     const ua = responseData.data.data.ua;
      //     layer.confirm(`未下载成功,先设置IDM/NDM User-Agent:<code>` + ua + `</code>,再复制直链下载!`,
      //       {
      //         btn: ['已下载,关闭弹窗', '复制UA', '未下载,复制直链'],
      //         closeBtn: 0,
      //       }, function (index) {
      //         layer.close(index);
      //       }, function (index) {
      //         GM_setClipboard(ua, "text");
      //         layer.msg(`UA复制成功!`);
      //         return false;
      //       }, function () {
      //         GM_setClipboard(downloadUrl, "text");
      //         layer.msg(`直链复制成功!`);
      //         layer.close(index);
      //       });
      //     // alert('下载链接: ' + downloadUrl);
      //   } catch (e) {
      //     console.error('解析响应时出错: ', e);
      //   }
      // }
    }

  });
});

// Intercept fetch requests
// (function () {
//   const originalFetch = window.fetch;
//   window.fetch = function () {
//     return originalFetch.apply(this, arguments).then(async response => {
//       const url = response.url;
//       if (url.includes('http://127.0.0.1:9999/api/v1/tasks')) {
//         try {
//           const responseClone = response.clone();
//           const responseData = await responseClone.json();
//           console.log('拦截请求:', responseData);
//         } catch (e) {
//           console.error('解析响应时出错: ', e);
//         }
//       }
//       return response;
//     });
//   };
// })();