Greasy Fork

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

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

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

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

    var html = location.href;
    var toast = Swal.mixin({
        imageUrl: 'https://basic.smartedu.cn/img/logo-new.59a73b97.png',
        allowOutsideClick: false,
        showConfirmButton: false,
        timerProgressBar: true,
        showCloseButton: true,
    });

    var message = {
        success: function (text) {
            toast.fire({ html: text, icon: 'success' });
        },
        error: function (text) {
            toast.fire({ html: text, icon: 'error' });
        },
        warning: function (text) {
            toast.fire({ html: text, icon: 'warning' });
        },
        info: function (text) {
            toast.fire({ html: text, icon: 'info' });
        },
        question: function (text) {
            toast.fire({ html: text, icon: 'question' });
        }
    };

    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();
        var hour = date.getHours();
        var hourtext = '';

        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) {
        var clickurl = document.getElementsByClassName("index-module_open_1MwDX");
        if (clickurl) {
            let link = document.querySelector(".index-module_link_QB2h9").title
            let tips = clickurl[0].innerHTML.replace("继续访问", "打开链接(安全)");
            clickurl[0].innerHTML = tips;
            message.info('<span><h3>链接获取成功!</h3><br>您可以右键点击下面的“点击直接跳转”按钮<br>并选择“链接另存为...”来另存教材PDF,<br>部分浏览器支持点击按钮后直接预览教材<br>(加载预览速度较慢)</span><br><a href="'+ link +'">点击直接跳转</a>');
            //setTimeout(function () {
            //    clickurl[0].click();
            //}, 3000);
        }
    }

    var 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>';
            var time = document.getElementById('time');
            if (time) {
                window.setInterval(function () {
                    time.innerHTML = timer();
                }, 500);
            }
        }, 2000);
    }

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

    var 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]+/, "").replace(/&subCatalog+=[A-Za-z0-9]+/, "").replace("assets_document", "x_url");
        }
    }

    if (html !== null && html.indexOf("assets_document") != -1) {
        message.success('<span>书籍地址获取成功,正在加载PDF页面请稍等,跳转过程中最好不要操作网页。 </span><br><a href="'+ GetUrl() +'">点击直接跳转</a>');
        setTimeout(function () {
            window.onload = window.location.href = GetUrl();
        }, 5000);
    }
})();