// ==UserScript== // @name Luogu Plus VScode CPH // @namespace http://tampermonkey.net/ // @version 0.2.3 // @author Andy_hpy // @icon https://www.luogu.com.cn/favicon.ico // @description 将Luogu题目测试用例发送到VS Code的CPH插件 // @match *://www.luogu.com.cn/* // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_addStyle // @connect 127.0.0.1 // @connect localhost // @require https://scriptcat.org/lib/5444/0.1.1/CPH%20API%E5%BA%93.js?sha384-jmi4a0QQDOtVuAdlWNOyhgKoJ7g8POo2oUPJX+c+BTBXz0cv2HUlk/1SDkGcti2s // @license AGPL-3.0 // ==/UserScript== /* ==UserConfig== CPH: port: title: 端口设置 description: CPH服务器的端口 default: 27121 type: number buttonStyle: title: 按钮是否使用实心样式 description: 按钮是否使用实心样式 type: checkbox default: false ==/UserConfig== */ cph = new CPH(GM_getValue('CPH.port', 27121)); function getTextContent(e) { if (typeof e.textContent !== 'undefined') { return e.textContent; } else { return e.innerText; } } async function getSample() { if (document.querySelector("div.io-sample")) { let sample = [], sampleIn = [], sampleOut = []; document.querySelectorAll("div.io-sample > div.io-sample-block:nth-child(1) > pre.lfe-code").forEach((pre) => { sampleIn.push(getTextContent(pre).trim()); }); document.querySelectorAll("div.io-sample > div.io-sample-block:nth-child(2) > pre.lfe-code").forEach((pre) => { sampleOut.push(getTextContent(pre).trim()); }); for (let i = 0; i < sampleIn.length; i++) { sample.push({ 'input': sampleIn[i], 'output': sampleOut[i] }); } return sample; } else { const html = await (await fetch(location.pathname)).text(); const matches = html.match(/