xmoj-script 1.2.46 → 1.2.48

Sign up to get free protection for your applications and to get access to all the features.
package/Update.json CHANGED
@@ -2296,6 +2296,28 @@
2296
2296
  }
2297
2297
  ],
2298
2298
  "Notes": "No release notes were provided for this release."
2299
+ },
2300
+ "1.2.47": {
2301
+ "UpdateDate": 1723181393030,
2302
+ "Prerelease": true,
2303
+ "UpdateContents": [
2304
+ {
2305
+ "PR": 670,
2306
+ "Description": "Fix RE"
2307
+ }
2308
+ ],
2309
+ "Notes": "No release notes were provided for this release."
2310
+ },
2311
+ "1.2.48": {
2312
+ "UpdateDate": 1723183783191,
2313
+ "Prerelease": true,
2314
+ "UpdateContents": [
2315
+ {
2316
+ "PR": 671,
2317
+ "Description": "允许在已结束的比赛下提交 #287"
2318
+ }
2319
+ ],
2320
+ "Notes": "No release notes were provided for this release."
2299
2321
  }
2300
2322
  }
2301
2323
  }
package/XMOJ.user.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // ==UserScript==
2
2
  // @name XMOJ
3
- // @version 1.2.46
3
+ // @version 1.2.48
4
4
  // @description XMOJ增强脚本
5
5
  // @author @XMOJ-Script-dev, @langningchen and the community
6
6
  // @namespace https://github/langningchen
@@ -2764,12 +2764,82 @@ async function main() {
2764
2764
  "referrer": location.href,
2765
2765
  "method": "POST",
2766
2766
  "body": (SearchParams.get("id") != null ? "id=" + SearchParams.get("id") : "cid=" + SearchParams.get("cid") + "&pid=" + SearchParams.get("pid")) + "&language=1&" + "source=" + encodeURIComponent(CodeMirrorElement.getValue()) + "&" + "enable_O2=on"
2767
- }).then((Response) => {
2767
+ }).then(async (Response) => {
2768
2768
  if (Response.redirected) {
2769
2769
  location.href = Response.url;
2770
2770
  } else {
2771
+ const text = await Response.text();
2772
+ if (text.indexOf("没有这个比赛!") !== -1 && new URL(location.href).searchParams.get("pid") !== null) {
2773
+ // Credit: https://github.com/boomzero/quicksubmit/blob/main/index.ts
2774
+ // Also licensed under GPL-3.0
2775
+ const contestReq = await fetch(
2776
+ "https://www.xmoj.tech/contest.php?cid=" + new URL(location.href).searchParams.get("cid"),
2777
+ {
2778
+ "credentials": "include",
2779
+ "headers": {
2780
+ "User-Agent":
2781
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0",
2782
+ "Accept":
2783
+ "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
2784
+ "Accept-Language": "en-US,en;q=0.5",
2785
+ "Upgrade-Insecure-Requests": "1",
2786
+ "Sec-Fetch-Dest": "document",
2787
+ "Sec-Fetch-Mode": "navigate",
2788
+ "Sec-Fetch-Site": "same-origin"
2789
+ },
2790
+ "referrer": "https://www.xmoj.tech/contest.php",
2791
+ "method": "GET",
2792
+ "mode": "cors",
2793
+ },
2794
+ );
2795
+ const res = await contestReq.text();
2796
+ if (
2797
+ contestReq.status !== 200 ||
2798
+ res.indexOf("比赛尚未开始或私有,不能查看题目。") !== -1
2799
+ ) {
2800
+ console.error(`Failed to get contest page!`);
2801
+ return;
2802
+ }
2803
+ const parser = new DOMParser();
2804
+ const dom = parser.parseFromString(res, "text/html");
2805
+ const contestProblems = [];
2806
+ const rows = (dom.querySelector(
2807
+ "#problemset > tbody",
2808
+ )).rows;
2809
+ for (let i = 0; i < rows.length; i++) {
2810
+ contestProblems.push(
2811
+ rows[i].children[1].textContent.substring(2, 6).replaceAll(
2812
+ "\t",
2813
+ "",
2814
+ ),
2815
+ );
2816
+ }
2817
+ rPID = contestProblems[new URL(location.href).searchParams.get("pid")];
2818
+ if (UtilityEnabled("DebugMode")) {
2819
+ console.log("Contest Problems:", contestProblems);
2820
+ console.log("Real PID:", rPID);
2821
+ }
2822
+ ErrorElement.style.display = "block";
2823
+ ErrorMessage.style.color = "red";
2824
+ ErrorMessage.innerText = "比赛已结束, 正在尝试像题目 " + rPID + " 提交";
2825
+ console.log("比赛已结束, 正在尝试像题目 " + rPID + " 提交");
2826
+ await fetch("https://www.xmoj.tech/submit.php", {
2827
+ "headers": {
2828
+ "content-type": "application/x-www-form-urlencoded"
2829
+ },
2830
+ "referrer": location.href,
2831
+ "method": "POST",
2832
+ "body": "id=" + rPID + "&language=1&" + "source=" + encodeURIComponent(CodeMirrorElement.getValue()) + "&" + "enable_O2=on"
2833
+ }).then(async (Response) => {
2834
+ if (Response.redirected) {
2835
+ location.href = Response.url;
2836
+ }
2837
+ console.log(await Response.text());
2838
+ });
2839
+
2840
+ }
2771
2841
  if (UtilityEnabled("DebugMode")) {
2772
- console.log("Submission failed! Response:", Response.text());
2842
+ console.log("Submission failed! Response:", text);
2773
2843
  }
2774
2844
  ErrorElement.style.display = "block";
2775
2845
  ErrorMessage.style.color = "red";
@@ -3712,6 +3782,11 @@ int main()
3712
3782
  let ParsedDocument = new DOMParser().parseFromString(Response, "text/html");
3713
3783
  let ErrorData = ParsedDocument.getElementById("errtxt").innerText;
3714
3784
  let MatchResult = ErrorData.match(/\what\(\): \[([A-Za-z0-9+\/=]+)\]/g);
3785
+ if (MatchResult === null) {
3786
+ GetDataButton.innerText = "获取数据失败";
3787
+ GetDataButton.disabled = false;
3788
+ return;
3789
+ }
3715
3790
  for (let i = 0; i < MatchResult.length; i++) {
3716
3791
  let Data = CryptoJS.enc.Base64.parse(MatchResult[i].substring(10, MatchResult[i].length - 1)).toString(CryptoJS.enc.Utf8);
3717
3792
  ApplyDiv.appendChild(document.createElement("hr"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmoj-script",
3
- "version": "1.2.46",
3
+ "version": "1.2.48",
4
4
  "description": "an improvement script for xmoj.tech",
5
5
  "main": "AddonScript.js",
6
6
  "scripts": {