// ==UserScript== // @name AlphaCoding Paste Unlocker // @match *://nuc.alphacoding.cn/* // @grant none // ==/UserScript== (function () { 'use strict'; // 创建一个按钮 const btn = document.createElement('button'); btn.textContent = '粘贴代码'; btn.classList.add('inline-flex', 'items-center', 'justify-center', 'whitespace-nowrap', 'rounded', 'border', 'border-transparent', 'bg-accent1-100', 'px-3', 'py-1.5', 'text-sm', 'font-medium', 'leading-4', 'text-accent1-700', 'mr-4'); // 位置样式(保持固定) Object.assign(btn.style, { position: 'fixed', top: '12px', right: '200px', zIndex: 9999, cursor: 'pointer' }); // 点击逻辑 btn.onclick = async () => { try { const text = await navigator.clipboard.readText(); const cm = document.querySelector('.CodeMirror')?.CodeMirror; if (cm) { cm.setValue(text); cm.focus(); alert('代码已注入 CodeMirror!'); } else { alert('未找到 CodeMirror 实例'); } } catch (err) { alert('无法读取剪贴板内容,请检查权限'); } }; // 注入到页面 document.body.appendChild(btn); })();