Greasy Fork

国家中小学智慧教育平台书籍下载

自动跳转到PDF页面

目前为 2023-02-03 提交的版本。查看 最新版本

// ==UserScript==
// @name         国家中小学智慧教育平台书籍下载
// @namespace    https://github.com/hmjz100/
// @version      0.1
// @description  自动跳转到PDF页面
// @author       Hmjz100
// @match        *://basic.smartedu.cn/*
// @match        *://*.zxx.edu.cn/*
// @icon         https://basic.smartedu.cn/favicon.ico
// @license      MIT
// @require      https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.all.min.js
// ==/UserScript==

(function() {
    let toast = Swal.mixin({
        imageUrl: 'https://basic.smartedu.cn/img/logo-new.59a73b97.png',
        allowOutsideClick: false,
        showConfirmButton: false,
        timer: 5000,
        timerProgressBar: true,
    });

    const message = {
        success: (text) => {
            toast.fire({html: text, icon: 'success'});
        },
        error: (text) => {
            toast.fire({html: text, icon: 'error'});
        },
        warning: (text) => {
            toast.fire({html: text, icon: 'warning'});
        },
        info: (text) => {
            toast.fire({html: text, icon: 'info'});
        },
        question: (text) => {
            toast.fire({html: text, icon: 'question'});
        }
    };
    var html = location.href
    function GetUrl () {
        if(html !== null && html.indexOf("catalogType") != -1){
            return html.replace(/&catalogType+=[A-Za-z0-9]+/,"")
        }
    }
    function GetLastUrl () {
        if(html !== null && html.indexOf("assets_document") != -1){
            return GetUrl().replace("assets_document","x_url")
        }
    }
    if(html !== null && html.indexOf("assets_document") != -1){
        message.success("<span>已替换该页面的书籍地址,正在加载PDF页面请稍等<br>如提示跳转到其他网站点击继续访问即可跳转PDF。</span>");
        setTimeout(function(){
            window.onload = window.location.href=GetLastUrl ();
        },5000)
    }
})();