Greasy Fork

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

自动跳转到PDF页面,精简页面

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

// ==UserScript==
// @name         国家中小学智慧教育平台书籍下载
// @namespace    https://github.com/hmjz100/
// @version      0.2
// @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==

window.onload = (function() {
    var html = location.href
    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'});
        }
    };

    //补0
    function repair(i){
        if (i >= 0 && i <= 9) {
            return "0" + i;
        } else {
            return i;
        }
    }


    function timer() {
        var date = new Date();//获取新的时间
        var year = date.getFullYear() //返回指定日期的年份
        var month = repair(date.getMonth() + 1);//月
        var day = repair(date.getDate());//日
        var hours = repair(date.getHours());//时
        var minute = repair(date.getMinutes());//分
        var second = repair(date.getSeconds());//秒

        //拼凑时间
        var curTime = year + "年 - " + month + "月 - " + day + "日&nbsp;&nbsp;" + hours + "时 : " + minute + "分 : " + second + "秒";
        return curTime //输出时间
    }

    function APM() {
        // 获取新的时间
        var date = new Date();

        // 设置默认文字
        let hourtext = ``;

        // 获取小时
        var hour = date.getHours();

        // 判断当前时间段
        if (hour >= 0 && hour <= 10) {
            hourtext = `早上好`;
        } else if (hour > 10 && hour <= 14) {
            hourtext = `中午好`;
        } else if (hour > 14 && hour <= 18) {
            hourtext = `下午好`;
        } else if (hour > 18 && hour <= 24) {
            hourtext = `晚上好`;
        }
        return hourtext//输出文字
    }

    if(html !== null && html.indexOf("goTip") != -1){
        let clickurl = document.getElementsByClassName("index-module_open_1MwDX")
        if (clickurl) {
            message.info("<span>正在加载PDF页面请稍等<br>请不要进行任何操作直至PDF打开!</span>");
            setTimeout(function(){
                clickurl[0].click()
            },5000)
        }
    }


    let notice = document.getElementsByClassName('index-module_header-content_Usvn5');//获取
    if (notice){
        setTimeout(function(){
            notice[0].innerHTML += '<div class="time" style="text-align:center"><span>'+APM()+',当前时间:<span id="time" style="color: #1d62ec">时间加载中</span>&nbsp;&nbsp;感谢您使用本脚本!</span></div>';
            let time = document.getElementById('time');
            if (time) {
                window.setInterval(function() {
                    time.innerHTML = timer();
                },500)
            }
        },2000)
    }


    console.log('[国家中小学智慧教育平台书籍下载]脚本运行成功')

    let topbar = document.getElementsByClassName("index-module_download-bar_1ZRtf theme-bar");
    if (topbar) {
        topbar[0].remove();
    }

    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)
    }
})();