Greasy Fork 支持简体中文。

osta-pdf-download

职业标准系统PDF下载

目前為 2022-07-28 提交的版本,檢視 最新版本

// ==UserScript==
// @name         osta-pdf-download
// @namespace    http://biaozhun.osta.org.cn/
// @version      0.1
// @description  职业标准系统PDF下载
// @author       vonsy
// @match        http://biaozhun.osta.org.cn/
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @run-at       document-idle
// @license      没有版本,违者不究
// ==/UserScript==

(function() {
    'use strict';
    console.log('等待DOM加载完成,倒数5秒.....');
    setTimeout(function() {
        let get = 'http://biaozhun.osta.org.cn/api/v1/profession/get/';
        let all = document.querySelectorAll('.table_data');
        for (let i = 0; i < all.length; i++) {
            let href = all[i].lastElementChild.firstElementChild.href
            let url = new URL(href);
            let code = url.searchParams.get("code");
            let name = all[i].children[2].textContent;

            var link = document.createElement("a");
            link.className = "download";
            link.innerText = name + 'PDF下载';
            link.href = 'javascript:void(0)';
            link.addEventListener('click', ()=>{
                console.log('下载' + name + 'PDF文件');
                let xhr = new XMLHttpRequest();
                let req = get + code;
                xhr.open("GET", req, false);
                xhr.onload = function(event){
                    let response = event.target.response;
                    let pdf = JSON.parse(response);
                    console.log('名称: ' + name);
                    console.log('编号: ' + code);
                    console.log('反馈结果: ' + pdf.msg);
                    console.log('反馈编码: ' + pdf.code);
                    let pdfWindow = window.open("")
                    pdfWindow.document.write(
                        "<iframe width='100%' height='100%' src='data:application/pdf;base64, " +
                        encodeURI(pdf.data) + "'></iframe>"
                    )
                };
                xhr.send();

            });
            all[i].children[2].textContent = '';
            all[i].children[2].appendChild(link);
        }
        console.log('执行完成.');
    }, 5000);
})();