Greasy Fork

智慧职教课件下载

[可以下载智慧职教课件]

// ==UserScript==
// @name         智慧职教课件下载
// @namespace    http://tampermonkey.net/
// @version      1.3
// @author       KEshan
// @description  [可以下载智慧职教课件]
// @match        *://zjy2.icve.com.cn/study/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    // 创建按钮
    const button = document.createElement('button');
    button.textContent = '下载课件';
    button.style.position = 'fixed';
    button.style.bottom = '20px';
    button.style.right = '20px';
    button.style.zIndex = '9999';
    button.style.padding = '10px 20px';
    button.style.backgroundColor = '#007BFF';
    button.style.color = 'white';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';

    // 按钮点击事件
    button.addEventListener('click', function () {
        // 获取标题元素
        const titleElement = document.querySelector('div.courseName');
        const folderName = titleElement
            ? titleElement.textContent.trim().replace(/[\\/:*?"<>|]/g, '_') // 替换非法字符
            : '默认标题'; // 设置默认标题

        // 获取页面上的所有图片
        const images = document.querySelectorAll('img');
        let count = 0;

        images.forEach(img => {
            const src = img.src; // 获取图片的 URL
            if (src.includes('_gen') && src.endsWith('/1.png')) {
                // 修改 URL
                const modifiedUrl = src
                    .replace('_gen', '') // 移除 _gen
                    .replace('/1.png', '') // 移除 /1.png
                    + `?response-content-disposition=attachment;filename=${folderName}`;

                // 创建隐藏的 <a> 元素触发下载
                const link = document.createElement('a');
                link.href = modifiedUrl;
                link.download = folderName;
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);

                count++;
            }
        });

    });

    // 将按钮添加到页面中
    document.body.appendChild(button);
})();