|
1 | 1 | // ==UserScript== |
2 | 2 | // @name XMOJ |
3 | | -// @version 0.3.184 |
| 3 | +// @version 0.3.185 |
4 | 4 | // @description XMOJ增强脚本 |
5 | 5 | // @author @langningchen |
6 | 6 | // @namespace https://github/langningchen |
7 | 7 | // @match http://*.xmoj.tech/* |
8 | 8 | // @match http://116.62.212.172/* |
9 | 9 | // @require https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.1/crypto-js.min.js |
10 | | -// @require https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.1/hmac-sha1.min.js |
11 | 10 | // @require https://cdn.bootcdn.net/ajax/libs/codemirror/6.65.7/codemirror.min.js |
12 | 11 | // @require https://cdn.bootcdn.net/ajax/libs/codemirror/6.65.7/mode/clike/clike.min.js |
13 | 12 | // @require https://cdn.bootcdn.net/ajax/libs/codemirror/6.65.7/addon/merge/merge.js |
14 | 13 | // @require https://cdn.bootcdn.net/ajax/libs/diff_match_patch/20121119/diff_match_patch_uncompressed.js |
15 | 14 | // @require https://cdn.bootcdn.net/ajax/libs/dompurify/3.0.2/purify.min.js |
16 | 15 | // @require https://cdn.bootcdn.net/ajax/libs/marked/4.3.0/marked.min.js |
17 | | -// @require https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.1/core.min.js |
18 | | -// @require https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.1/md5.min.js |
19 | 16 | // @grant GM_registerMenuCommand |
20 | 17 | // @grant GM_xmlhttpRequest |
21 | 18 | // @grant GM_setClipboard |
@@ -2927,6 +2924,107 @@ else { |
2927 | 2924 | CurrentElement.innerText = TimeToStringTime(Temp[0]) + "/" + SizeToStringSize(Temp[1]); |
2928 | 2925 | } |
2929 | 2926 | if (document.getElementById("apply_data")) { |
| 2927 | + let ApplyDiv = document.getElementById("apply_data").parentElement; |
| 2928 | + let GetDataButton = document.createElement("button"); |
| 2929 | + GetDataButton.className = "ms-2 btn btn-outline-secondary"; |
| 2930 | + GetDataButton.innerText = "获取数据"; |
| 2931 | + ApplyDiv.appendChild(GetDataButton); |
| 2932 | + GetDataButton.addEventListener("click", async () => { |
| 2933 | + GetDataButton.disabled = true; |
| 2934 | + GetDataButton.innerText = "正在获取数据..."; |
| 2935 | + let PID = localStorage.getItem("UserScript-Solution-" + SearchParams.get("sid") + "-Problem"); |
| 2936 | + let Code = ""; |
| 2937 | + if (localStorage.getItem(`UserScript-Problem-${PID}-IOFilename`) !== null) { |
| 2938 | + Code = `#define IOFile "${localStorage.getItem(`UserScript-Problem-${PID}-IOFilename`)}"\n`; |
| 2939 | + } |
| 2940 | + Code += `#include <bits/stdc++.h> |
| 2941 | +using namespace std; |
| 2942 | +string Base64Encode(string Input) |
| 2943 | +{ |
| 2944 | + const string Base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
| 2945 | + string Output; |
| 2946 | + for (int i = 0; i < Input.length(); i += 3) |
| 2947 | + { |
| 2948 | + Output.push_back(i + 0 > Input.length() ? '=' : Base64Chars[(Input[i + 0] & 0xfc) >> 2]); |
| 2949 | + Output.push_back(i + 1 > Input.length() ? '=' : Base64Chars[((Input[i + 0] & 0x03) << 4) + ((Input[i + 1] & 0xf0) >> 4)]); |
| 2950 | + Output.push_back(i + 2 > Input.length() ? '=' : Base64Chars[((Input[i + 1] & 0x0f) << 2) + ((Input[i + 2] & 0xc0) >> 6)]); |
| 2951 | + Output.push_back(i + 3 > Input.length() ? '=' : Base64Chars[Input[i + 2] & 0x3f]); |
| 2952 | + } |
| 2953 | + return Output; |
| 2954 | +} |
| 2955 | +int main() |
| 2956 | +{ |
| 2957 | +#ifdef IOFile |
| 2958 | + freopen(IOFile ".in", "r", stdin); |
| 2959 | + freopen(IOFile ".out", "w", stdout); |
| 2960 | +#endif |
| 2961 | + string Input; |
| 2962 | + while (1) |
| 2963 | + { |
| 2964 | + char Data = getchar(); |
| 2965 | + if (Data == EOF) |
| 2966 | + break; |
| 2967 | + Input.push_back(Data); |
| 2968 | + } |
| 2969 | + throw runtime_error("[" + Base64Encode(Input.c_str()) + "]"); |
| 2970 | + return 0; |
| 2971 | +}`; |
| 2972 | + |
| 2973 | + await fetch("http://www.xmoj.tech/submit.php", { |
| 2974 | + "headers": { |
| 2975 | + "content-type": "application/x-www-form-urlencoded" |
| 2976 | + }, |
| 2977 | + "referrer": "http://www.xmoj.tech/submitpage.php?id=" + PID, |
| 2978 | + "method": "POST", |
| 2979 | + "body": "id=" + PID + "&" + |
| 2980 | + "language=1&" + |
| 2981 | + "source=" + encodeURIComponent(Code) + "&" + |
| 2982 | + "enable_O2=on" |
| 2983 | + }); |
| 2984 | + |
| 2985 | + let SID = await fetch("http://www.xmoj.tech/status.php").then((Response) => { |
| 2986 | + return Response.text(); |
| 2987 | + }).then((Response) => { |
| 2988 | + let ParsedDocument = new DOMParser().parseFromString(Response, "text/html"); |
| 2989 | + return ParsedDocument.querySelector("#result-tab > tbody > tr:nth-child(1) > td:nth-child(2)").innerText; |
| 2990 | + }); |
| 2991 | + |
| 2992 | + await new Promise((Resolve) => { |
| 2993 | + let Interval = setInterval(async () => { |
| 2994 | + await fetch("status-ajax.php?solution_id=" + SID).then((Response) => { |
| 2995 | + return Response.text(); |
| 2996 | + }).then((Response) => { |
| 2997 | + if (Response.split(",")[0] >= 4) { |
| 2998 | + clearInterval(Interval); |
| 2999 | + Resolve(); |
| 3000 | + } |
| 3001 | + }); |
| 3002 | + }, 500); |
| 3003 | + }); |
| 3004 | + |
| 3005 | + await fetch(`http://www.xmoj.tech/reinfo.php?sid=${SID}`).then((Response) => { |
| 3006 | + return Response.text(); |
| 3007 | + }).then((Response) => { |
| 3008 | + let ParsedDocument = new DOMParser().parseFromString(Response, "text/html"); |
| 3009 | + let ErrorData = ParsedDocument.getElementById("errtxt").innerText; |
| 3010 | + let MatchResult = ErrorData.match(/\what\(\): \[([A-Za-z0-9+\/=]+)\]/g); |
| 3011 | + for (let i = 0; i < MatchResult.length; i++) { |
| 3012 | + let Data = CryptoJS.enc.Base64.parse(MatchResult[i].substring(10, MatchResult[i].length - 1)).toString(CryptoJS.enc.Utf8); |
| 3013 | + ApplyDiv.appendChild(document.createElement("hr")); |
| 3014 | + ApplyDiv.appendChild(document.createTextNode("数据" + (i + 1) + ":")); |
| 3015 | + let CodeElement = document.createElement("div"); |
| 3016 | + ApplyDiv.appendChild(CodeElement); |
| 3017 | + CodeMirror(CodeElement, { |
| 3018 | + value: Data, |
| 3019 | + theme: (UtilityEnabled("DarkMode") ? "darcula" : "default"), |
| 3020 | + lineNumbers: true, |
| 3021 | + readOnly: true |
| 3022 | + }).setSize("100%", "auto"); |
| 3023 | + } |
| 3024 | + GetDataButton.innerText = "获取数据成功"; |
| 3025 | + GetDataButton.disabled = false; |
| 3026 | + }); |
| 3027 | + }); |
2930 | 3028 | document.getElementById("apply_data").addEventListener("click", () => { |
2931 | 3029 | let ApplyElements = document.getElementsByClassName("data"); |
2932 | 3030 | for (let i = 0; i < ApplyElements.length; i++) { |
|
0 commit comments