// ==UserScript== // @name 信友队 Better! // @namespace http://tampermonkey.net/ // @version 1.0.0 // @description 优化信友队 // @author Andy_hpy // @match *://*.xinyoudui.com/* // @icon https://www.xinyoudui.com/xyd_icon.png // @grant GM_addStyle // @grant GM_xmlhttpRequest // @connect 127.0.0.1 // @connect localhost // @run-at document-start // @require https://scriptcat.org/lib/5444/0.1.1/CPH%20API%E5%BA%93.js?sha384-jmi4a0QQDOtVuAdlWNOyhgKoJ7g8POo2oUPJX+c+BTBXz0cv2HUlk/1SDkGcti2s // @license AGPL-3.0 // @early-start // ==/UserScript== cph = new CPH(27121); async function addcss() { GM_addStyle(` .cgh-btn { float: right; height: 30px; background-color: rgb(96, 165, 250); color: white; margin: 10px; border: 1px solid rgb(96, 165, 250); border-radius: 4px; cursor: pointer; } .cgh-btn:hover { background-color:rgba(96, 165, 250, 0.8); } `); } async function addbtn() { const btn = document.createElement('div'); btn.className = 'contest-ant-space-item'; btn.innerHTML = ''; btn.addEventListener('click', async () => { cph.send({ name: problemData.name, group: problemData.group, displayName: problemData.displayName, tests: problemData.test.map((t, idx) => ({ ...t, id: idx })), timeLimit: problemData.timeLimit, memoryLimit: problemData.memoryLimit, url: problemData.url, testType: "single", input: { type: "stdin" }, output: { type: "stdout" }, languages: { java: { mainClass: "Main", taskClass: "" } }, batch: { id: cph.randomUUID(), size: 1 } }); }); if (document.querySelector("div.contest-ant-space-item div[data-testid=submissionStatus] div")) { document.querySelector("div.contest-ant-space-item div[data-testid=submissionStatus] div").before(btn); } else if (document.querySelector("#rc-tabs-0-panel-statement > div > div.contest-ant-space.contest-ant-space-vertical\ .contest-ant-space-gap-row-small.contest-ant-space-gap-col-small > div:nth-child(2) > div > div:nth-child(2)")) { document.querySelector("#rc-tabs-0-panel-statement > div > div.contest-ant-space.contest-ant-space-vertical\ .contest-ant-space-gap-row-small.contest-ant-space-gap-col-small > div:nth-child(2) > div > div:nth-child(2)").after(btn); } } let problemData = {}; async function hijackFetch() { const originalFetch = unsafeWindow.fetch; unsafeWindow.fetch = async function (...args) { const response = await originalFetch(...args); const url = args[0]; if (/^http[s]?:\/\/oss\.aws\.turingstar\.com\.cn\/\d+$/.test(url) || /^http[s]?:\/\/staticw\.turingstar\.com\.cn\/\d+\/\w+\/\d+$/.test(url)) { const data = await response.clone().json(); problemData = { displayName: data.nameZh, name: location.href.split('/')[6], group: '信友队', test: JSON.parse(data.example), url: location.href, timeLimit: data.timeLimit, memoryLimit: data.memoryLimit / 1024, }; addcss(); setInterval(() => { if (!document.querySelector("button.cgh-btn")) { try { addbtn(); } catch (e) { } } }, 250); } return response; }; } hijackFetch();