Greasy Fork

来自缓存

Greasy Fork is available in English.

解除HUST课程平台作业复制粘贴限制

解除HUST作业页面的所有限制:1. 文本复制粘贴;2. 图片粘贴;3. 图片拖拽上传。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         解除HUST课程平台作业复制粘贴限制
// @namespace    http://tampermonkey.net/
// @version      3.0
// @description  解除HUST作业页面的所有限制:1. 文本复制粘贴;2. 图片粘贴;3. 图片拖拽上传。
// @author       dy_boat
// @match        *://smartcourse.hust.edu.cn/mooc-ans/*
// @grant        unsafeWindow
// @grant        GM_addStyle
// @license      MIT
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // --- Part 1: 通用限制解除 (立即执行) ---
    console.log('[解除HUST课程平台作业复制粘贴限制] 脚本启动。');
    GM_addStyle(`* { user-select: auto !important; -webkit-user-select: auto !important; }`);

    const eventsToBypass = ['copy', 'paste', 'cut', 'contextmenu', 'selectstart'];
    eventsToBypass.forEach(eventName => {
        document.addEventListener(eventName, event => {
            event.stopImmediatePropagation();
        }, true);
    });
    console.log('通用事件拦截器已部署。');

    // --- Part 2: 针对 UEditor 的高级拦截与配置修改 (智能监控并执行) ---

    // 持续监控,直到成功修改 UE 核心对象和配置
    const observer = new MutationObserver((mutations, obs) => {
        const UE = unsafeWindow.UE;
        const UEDITOR_CONFIG = unsafeWindow.UEDITOR_CONFIG;

        let isUEPatched = false;
        let isConfigPatched = false;

        // --- 模块 A: 破解文本粘贴限制 ---
        if (UE && UE.Editor && UE.Editor.prototype.addListener && !UE.Editor.prototype._addListener_original) {
            UE.Editor.prototype._addListener_original = UE.Editor.prototype.addListener;
            UE.Editor.prototype.addListener = function(types, listener) {
                if (types === 'beforepaste') {
                    console.log('成功拦截并阻止 "beforepaste" (文本粘贴限制) 事件绑定!');
                    return;
                }
                return this._addListener_original(types, listener);
            };
            console.log('已劫持 UEditor 的 addListener 方法。');
            isUEPatched = true;
        }

        // --- 模块 B: 破解图片粘贴/拖拽限制 ---
        if (UEDITOR_CONFIG) {
            let configChanged = false;
            // 检查并强制开启图片粘贴功能
            if (UEDITOR_CONFIG.disablePasteImage === true) {
                UEDITOR_CONFIG.disablePasteImage = false;
                console.log('发现图片粘贴被禁用,已强制开启!');
                configChanged = true;
            }
            // 检查并强制开启图片拖拽功能
            if (UEDITOR_CONFIG.disableDraggable === true) {
                UEDITOR_CONFIG.disableDraggable = false;
                console.log('发现图片拖拽被禁用,已强制开启!');
                configChanged = true;
            }
            if (configChanged) {
                 isConfigPatched = true;
            }
        }

        // 如果两个任务都完成了,就停止监控
        // (注意:配置项可能在UE对象出现前就已存在,所以分开判断)
        if ( (UE && UE.Editor && UE.Editor.prototype._addListener_original) && UEDITOR_CONFIG && UEDITOR_CONFIG.disablePasteImage === false) {
             console.log('所有破解任务完成,停止监控。');
             obs.disconnect();
        }
    });

    // 启动监控
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });
})();