lintanger 发表于 2022-8-23 09:08

【油猴脚本】夸克网盘直链下载

夸克网盘对较大文件需要安装客户端才能下载,分享一个油猴脚本,使夸克网盘大文件可直接通过浏览器或搭配IDM下载
脚本地址:https://greasyfork.org/zh-CN/scripts/448675   
注意:1.使用脚本需先保存到自己网盘内。2.无法直接下载整个文件夹。3.一次下载多个文件时浏览器可能会拦截弹窗,需要手动允许。

使用方法:



// ==UserScript==
// @name         夸克网盘直链下载
// @version      1.1
// @namespace    https://pan.quark.cn/list
// @Description解除夸克网盘下载限制,直接在浏览器中下载
// @author       Lingo Wang
// @license      MIT

// @match      https://pan.quark.cn/list*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=quark.cn
// @grant      GM_xmlhttpRequest
// @grant      GM_log
// @grant window.onurlchange
// ==/UserScript==

(function () {
    'use strict';
    GM_log('quark download is running.');

    setInterval(gmMain, 250);
    const fidAttrName = 'data-row-key';

    function gmMain() {
      const checkboxes = document.getElementsByClassName('ant-checkbox-input');
      if (checkboxes === undefined || checkboxes.length <= 1) {
            console.log('document element not loaded yet');
            return;
      }

      // checkboxes.length > 1
      console.log('document element loaded, start dealing download btn');
      for (let i = 0; i < checkboxes.length; i++) {
            checkboxes.addEventListener('change', (event) => {
                if (event.currentTarget.checked) {
                  addDownloadBtnListener();
                }
            })
      }

      // flow download btn
      addFlowDownloadBtnListener();
    }

    function addDownloadBtnListener() {
      let downloadBtn = getDownloadBtn();
      downloadBtn.replaceWith(downloadBtn.cloneNode(true));   // remove all event listener
      downloadBtn = getDownloadBtn();

      downloadBtn.addEventListener('click', () => {
            let fids = getSelectedFids();
            download(fids);
      })
    }

    function addFlowDownloadBtnListener() {
      for (const btn of getFlowDownloadBtns()) {
            btn.replaceWith(btn.cloneNode(true));   // remove all event listener
      }

      for (const btn of getFlowDownloadBtns()) {
            btn.addEventListener('click', () => {
                const fid = btn.parentElement.parentElement.parentElement.parentElement.parentElement.getAttribute(fidAttrName);
                download();
            })
      }
    }

    function download(fids) {
      GM_xmlhttpRequest({
            method: "POST",
            url: "https://drive.quark.cn/1/clouddrive/file/download?pr=ucpro&fr=pc&ve=2.1.5",
            headers: {
                "Content-Type": "application/json;charset=utf-8"
            },
            data: JSON.stringify({"fids": fids}),
            onload: function (res) {
                console.log('get real download url, fids: %o, res: ', fids, res.responseText);
                let resData = JSON.parse(res.responseText).data;
                if (resData === undefined || resData.length === 0) {
                  console.log('error!, data is empty. request fids: ', fids);
                  alert('获取直链失败, 请尝试刷新页面!注意,文件夹不支持直链下载!')
                  return;
                } else {
                  console.log('get real download url, size: ', resData.length)
                }

                resData.forEach(o => window.open(o.download_url));
            }
      });
    }

    function getDownloadBtn() {
      let btnGroup = document.getElementsByClassName('ant-btn btn-file');
      let downloadBtn;
      for (let i = 0; i < btnGroup.length; i++) {
            if ('下载' === btnGroup.firstElementChild.innerText) {
                downloadBtn = btnGroup;
            }
      }
      return downloadBtn;
    }

    function getFlowDownloadBtns() {
      return document.getElementsByClassName('hover-oper-item hoitem-down');
    }

    function getSelectedFids() {
      const checkboxes = document.getElementsByClassName('ant-checkbox-input');
      let fids = [];
      for (let i = 0; i < checkboxes.length; i++) {
            if (checkboxes.checked) {
                const fid = checkboxes.parentElement.parentElement.parentElement.parentElement.parentElement.getAttribute('data-row-key');
                if (fid !== undefined && fid !== '') {
                  fids.push(fid);
                }
            }
      }
      return fids;
    }
})();

cocclove 发表于 2022-8-23 09:08

谢谢分享!

zbc222222 发表于 2022-8-23 09:25


感谢楼主的分享

忽而因为 发表于 2022-8-23 09:26

感谢楼主分享

yifazhi 发表于 2022-8-23 09:26

多谢楼主分享

yjpkhali2 发表于 2022-8-23 09:27

谢谢@Thanks!

350552632 发表于 2022-8-23 09:29

谢谢大佬分享

zhoudaxia1819 发表于 2022-8-23 09:32

谢谢分享

w501539118 发表于 2022-8-23 09:53

6666

q2650115652 发表于 2022-8-23 09:59


支持楼主,谢谢分享。
页: [1] 2
查看完整版本: 【油猴脚本】夸克网盘直链下载