Auto downloader for lanzoux

auto download in lanzoux website

// ==UserScript==
// @name         Auto downloader for lanzoux
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description auto download in lanzoux website
// @author       You
// @match        https://www.lanzoux.com/*
// @match        https://*.lanzous.com/*
// @match        https://*.baidupan.com/*
// @grant        none
// ==/UserScript==

function pollingQuery(selector, interval, timeout) {
  const deadline = +new Date() + timeout;
  let timer = null;

  return new Promise((resolve, reject) => {
    function query() {
      const result = document.querySelector(selector);
      if (result) {
        resolve(result);
        if (timer) {
          window.clearTimeout(timer);
          timer = null;
        }
      } else if (+new Date() > deadline) {
        // timeout
        reject();
      } else {
        timer = setTimeout(query, interval);
      }
    }
    query();
  });
}

(function () {
  'use strict';
  console.log('script started');

  switch (true) {
    case /.*\.lanzou[x|s].com\/[^\/]+/.test(location.href):
      // base
      pollingQuery('#go>a', 200, 3 * 1000)
        .then((el) => {
          console.log(el.href);
          location.href = el.href;
        })
        .catch(() => {
          console.log('failed');
        });
      break;
    case /baidupan.com/.test(location.href):
      // download
      pollingQuery('#sub>div', 200, 3 * 1000)
        .then((el) => {
          console.log(el.text);
          setTimeout(() => {
            el.click();
            pollingQuery('#go>a', 200, 3 * 1000)
              .then((el) => {
                console.log(el.href);
                el.click();
              })
              .catch(() => {
                console.log('failed');
              });
          }, 3e3);
        })
        .catch(() => {
          console.log('failed');
        });

      break;
  }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址