Studydrive Downloader

Download Studydrive documents

目前为 2024-09-24 提交的版本。查看 最新版本

// ==UserScript==
// @name         Studydrive Downloader
// @namespace    http://tampermonkey.net/
// @version      2024-09-24
// @description  Download Studydrive documents
// @author       You
// @match        https://www.studydrive.net/*/doc/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=studydrive.net
// @grant        GM_download
// @license MIT
// ==/UserScript==

(function() {
	'use strict';

	async function download() {
		if(!PDFView.pdfDocument.getData) {
			alert("ERROR: Could not get pdf data, maybe the mechanics have changed");
		}

		const blobData = await PDFView.pdfDocument.getData();
		const blobUrl = await URL.createObjectURL(new Blob([blobData], {
			type: "application/pdf"
		}));

		let fileName;
		try {
			fileName = document.querySelector("#main-container h1").textContent;
		} catch {
			fileName = "document.pdf"; // Fallback name
		}

		GM_download(blobUrl, fileName);
	}

	function setupDownloadButton() {
		const downloadButton = document.querySelector("button[data-specific-auth-trigger=download]");
		if (downloadButton) {
			// Replace original download button with copy so that we get rid of the original click listeners
			const buttonCopy = downloadButton.cloneNode(true);
			downloadButton.parentNode.replaceChild(buttonCopy, downloadButton);
			buttonCopy.addEventListener('click', download);
		}
	}

	setupDownloadButton();
})();
长期地址
遇到问题?请前往 GitHub 提 Issues,或加Q群1031348184

赞助商

Fishcpy

广告

Rainyun

注册一下就行

Rainyun

一年攒够 12 元