Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit fb71710

Browse files
author
Chen LangNing
authored
Merge pull request #566 from langningchen/langningchen/issue524
允许直接获取数据,而不是申请数据
2 parents 7ae45eb + 202daac commit fb71710

2 files changed

Lines changed: 112 additions & 4 deletions

File tree

Update.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,16 @@
623623
"Description": "解决无法在题目板块发布讨论"
624624
}
625625
]
626+
},
627+
"0.3.185": {
628+
"UpdateDate": 1696059816627,
629+
"Prerelease": true,
630+
"UpdateContents": [
631+
{
632+
"PR": 566,
633+
"Description": "允许直接获取数据,而不是申请数据"
634+
}
635+
]
626636
}
627637
}
628638
}

XMOJ.user.js

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
// ==UserScript==
22
// @name XMOJ
3-
// @version 0.3.184
3+
// @version 0.3.185
44
// @description XMOJ增强脚本
55
// @author @langningchen
66
// @namespace https://github/langningchen
77
// @match http://*.xmoj.tech/*
88
// @match http://116.62.212.172/*
99
// @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
1110
// @require https://cdn.bootcdn.net/ajax/libs/codemirror/6.65.7/codemirror.min.js
1211
// @require https://cdn.bootcdn.net/ajax/libs/codemirror/6.65.7/mode/clike/clike.min.js
1312
// @require https://cdn.bootcdn.net/ajax/libs/codemirror/6.65.7/addon/merge/merge.js
1413
// @require https://cdn.bootcdn.net/ajax/libs/diff_match_patch/20121119/diff_match_patch_uncompressed.js
1514
// @require https://cdn.bootcdn.net/ajax/libs/dompurify/3.0.2/purify.min.js
1615
// @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
1916
// @grant GM_registerMenuCommand
2017
// @grant GM_xmlhttpRequest
2118
// @grant GM_setClipboard
@@ -2927,6 +2924,107 @@ else {
29272924
CurrentElement.innerText = TimeToStringTime(Temp[0]) + "/" + SizeToStringSize(Temp[1]);
29282925
}
29292926
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+
});
29303028
document.getElementById("apply_data").addEventListener("click", () => {
29313029
let ApplyElements = document.getElementsByClassName("data");
29323030
for (let i = 0; i < ApplyElements.length; i++) {

0 commit comments

Comments
 (0)