pdf 转换

dx 网上大学 pdf

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         pdf 转换
// @namespace    http://tampermonkey.net/
// @version      2024-07-07
// @description  dx 网上大学 pdf
// @author       hn_lzy
// @license      MIT
// @match        *://kc.zhixueyun.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zhixueyun.com
// @grant        none
// @connect      self
// ==/UserScript==
(function() {
    'use strict';
    
    console.log('Script is running on kc.zhixueyun.com');
    const originalFetch = window.fetch;
    console.log('--------------test pdf------------');
    window.fetch = function(...args) {
        return originalFetch.apply(this, args).then(response => {
            if (response.headers.get('Content-Type') === 'application/pdf') {
                console.log('Intercepted PDF response:', response.url);
                console.log('test url');
                return response.blob().then(blob => {
                    // 创建一个临时的a标签用于下载
                    console.log(blob);
                    const a = document.createElement('a');
                    a.style.display= 'none';
                    a.href = URL.createObjectURL(blob);
                    a.download =prompt('给下载的pdf文件命名:');
                    document.body.appendChild(a);
                    a.click();
                    document.body.removeChild(a);
                    URL.revokeObjectURL(a.href);
                });
            }
            // 对于非PDF响应,返回原始的Response对象
            return response;
        }).catch(error => {
            console.error('Fetch error:', error);
            // 根据需要处理错误,或者可以重新抛出错误
            throw error;
        });
    };
})();