版本比较
Some 插件s
正文
增加 0 行删除 133 行
725 行未改动全部展开726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862725 行未改动全部展开 isInControls: (node) => isInControls(node) };})();```
#### OJ题面 & 题解复制面板```javascript// ==UserScript==// @name OJ题面&题解复制面板// @namespace http://tampermonkey.net/// @version 0.3// @description 提取UiContextNew题面 / 批量拉取solution raw,悬浮剪贴板样式块,点击复制(兼容http内网)// @author You// @match http://192.168.110.12/p/*// @grant none// ==/UserScript==
(function() { 'use strict';
// 悬浮容器,固定在右下角 const panelWrap = document.createElement('div'); panelWrap.style.position = 'fixed'; panelWrap.style.bottom = '20px'; panelWrap.style.right = '20px'; panelWrap.style.zIndex = '99999'; panelWrap.style.maxWidth = '320px'; panelWrap.style.maxHeight = '70vh'; panelWrap.style.overflowY = 'auto'; panelWrap.style.display = 'flex'; panelWrap.style.flexDirection = 'column'; panelWrap.style.gap = '8px'; document.body.appendChild(panelWrap);
// ✅ 兼容HTTP页面的复制函数(解决navigator.clipboard undefined) async function copyText(text) { const ta = document.createElement('textarea'); ta.value = text; ta.style.position = 'absolute'; ta.style.left = '-9999px'; document.body.appendChild(ta); ta.select(); const ok = document.execCommand('copy'); document.body.removeChild(ta); return ok; }
// 创建单个复制卡片 function createCopyBlock(text, title) { const block = document.createElement('div'); block.style.background = '#fff'; block.style.border = '1px solid #ccc'; block.style.borderRadius = '6px'; block.style.padding = '10px'; block.style.cursor = 'pointer'; block.style.boxShadow = '0 2px 8px #00000022'; block.style.fontSize = '13px'; block.style.whiteSpace = 'pre-wrap'; block.style.overflow = 'hidden'; block.style.textOverflow = 'ellipsis'; block.style.maxHeight = '120px'; block.title = `点击复制【${title}】`; block.textContent = text.slice(0,300) + (text.length>300 ? '\n...(太长截断)' : '');
block.onclick = async () => { try { const success = await copyText(text); if(success){ block.style.background = '#d9f7be'; setTimeout(()=>block.style.background='#fff', 800); }else{ alert("复制失败"); } }catch(e){ console.error(e); alert("复制异常:"+e.message); } } panelWrap.appendChild(block); }
// ---------------------- 题目页面 /p/* ---------------------- async function handleProblemPage(){ if(!window.UiContextNew) return; try{ const outer = JSON.parse(window.UiContextNew); const pdocContent = JSON.parse(outer.pdoc.content); const zhText = pdocContent.zh; createCopyBlock(zhText, "中文题面 zh"); }catch(err){ console.error("解析UiContextNew失败",err); createCopyBlock("解析失败:"+err.message, "题面解析错误"); } }
// ---------------------- 题解页面 /p/*/solution ---------------------- async function get_raw(url) { try { const resp = await fetch(url); if (!resp.ok) { console.error("获取失败,HTTP状态码:", resp.status); return `请求失败 status:${resp.status}`; } const text = await resp.text(); console.log("拿到raw文本内容:\n", text); return text; } catch (err) { console.error("请求异常", err); return "网络异常:"+err.message; } } async function handleSolutionPage(){ const t = document.getElementsByClassName('typo richmedia collapsible-content'); for(let i = 0; i < t.length; i ++){ const rawUrl = t[i].dataset.rawUrl; const fullUrl = location.origin + rawUrl; const rawTxt = await get_raw(fullUrl); createCopyBlock(rawTxt, `题解raw #${i+1}`); } }
// 路由判断 function routeCheck(){ const path = location.pathname; if(path.match(/^\/p\/.+\/solution$/)){ handleSolutionPage(); }else if(path.match(/^\/p\//)){ handleProblemPage(); } }
window.addEventListener('load', ()=>{ setTimeout(routeCheck, 800); })
})();```