Greasy Fork

Greasy Fork is available in English.

Monaco/头歌/学习通 通用代码增强工具

统一适配 Monaco / 头歌 / CodeMirror 编辑器:提取 + 复制 + 写入

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Monaco/头歌/学习通 通用代码增强工具
// @namespace    http://tampermonkey.net/
// @version      4.1
// @description  统一适配 Monaco / 头歌 / CodeMirror 编辑器:提取 + 复制 + 写入
// @match        *://*.chaoxing.com/*
// @match        *://*.edu.cn/*
// @match        *://*.educoder.net/*
// @match        *://*.headgo*/*
// @grant        none
// @run-at       document-start
// @author       sikoll
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 阻止页面阻止粘贴
    document.addEventListener('paste', function(e) {
        e.stopImmediatePropagation();
    }, true);

    // 允许所有输入框粘贴
    const allowPaste = () => {
        document.querySelectorAll('input, textarea, [contenteditable="true"]').forEach(el => {
            el.onpaste = null;
            el.style.userSelect = 'text';
        });
    };

    // 监听动态加载的iframe(学习通常用iframe编辑器)
    const observer = new MutationObserver(() => {
        allowPaste();
        document.querySelectorAll('iframe').forEach(iframe => {
            try {
                if (iframe.contentDocument) {
                    iframe.contentDocument.addEventListener('paste', e => e.stopImmediatePropagation(), true);
                    const frameObserver = new MutationObserver(allowPaste);
                    frameObserver.observe(iframe.contentDocument.body, { childList: true, subtree: true });
                }
            } catch(e) {}
        });
    });

    observer.observe(document.body, { childList: true, subtree: true });
    allowPaste();

    console.log('✅ 学习通粘贴限制已解除!Ctrl+V 试试看');
})();