小雅爬爬爬

爬取课件url

当前为 2024-03-04 提交的版本,查看 最新版本

// ==UserScript==
// @name        小雅爬爬爬
// @match      *://ccnu.ai-augmented.com/*
// @grant       none
// @description 爬取课件url
// @license MIT
// @author   Yi
// @version 1.0.1
// @namespace https://gf.qytechs.cn/users/1268039
// ==/UserScript==

// 定义要抓取的后缀名
var extensions = [".doc", ".pdf", ".docx", ".ppt", ".pptx", ".xls", ".xlsx"];

// 创建一个元素,用于显示抓取到的 url
var list = document.createElement("div");
list.style.position = "fixed";
list.style.top = "10px";
list.style.right = "0";
list.style.width = "300px";
list.style.height = "10%";
list.style.overflow = "auto";
list.style.backgroundColor = "yellow";
list.style.zIndex = "9999";
list.style.padding = "10px";
list.style.border = "1px solid black";
list.innerHTML = "<h3>抓取到的 url</h3>";
document.body.appendChild(list);

// 创建一个数组,用于存储已经抓取过的 url
var crawled_urls = [];

// 监听 xhr 请求,检查响应的 url 是否符合条件
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
  this.addEventListener("load", function() {
    // 如果 url 包含指定的后缀名之一,且没有被抓取过
    for (var i = 0; i < extensions.length; i++) {
      if (url.includes(extensions[i]) && !crawled_urls.includes(url)) {
        // 将 url 添加到已抓取的数组中
        crawled_urls.push(url);
        // 发送一个新的 xhr 请求,获取真正的下载地址
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url, true);
        xhr.onload = function() {
          // 如果响应的文本中包含一个以 http 或 https 开头的 url,将其添加到列表中
          // 在此之前,先将响应的文本中的 "}}" 和引号替换为空字符串,去掉多余的符号
          var text = xhr.responseText.replace("}}", "").replace(/"/g, "");
          var match = text.match(/(http|https):\/\/\S+/);
          if (match) {
            var link = document.createElement("a");
            link.href = match[0];
            link.target = "_blank";
            link.textContent = match[0];
            list.appendChild(link);

list.appendChild(document.createElement("br"));
          }
        };
        xhr.send();
        break;
      }
    }
  });
  open.call(this, method, url, async, user, pass);
};

QingJ © 2025

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