xmoj-script 2.4.2 → 2.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/Update.json +22 -0
  2. package/XMOJ.user.js +57 -118
  3. package/package.json +1 -1
package/Update.json CHANGED
@@ -3102,6 +3102,28 @@
3102
3102
  }
3103
3103
  ],
3104
3104
  "Notes": "修复“NaN年前“"
3105
+ },
3106
+ "2.4.3": {
3107
+ "UpdateDate": 1759414259108,
3108
+ "Prerelease": true,
3109
+ "UpdateContents": [
3110
+ {
3111
+ "PR": 865,
3112
+ "Description": "删除获取数据功能"
3113
+ }
3114
+ ],
3115
+ "Notes": "因为它利用的bug被修复了"
3116
+ },
3117
+ "2.4.4": {
3118
+ "UpdateDate": 1759417362937,
3119
+ "Prerelease": true,
3120
+ "UpdateContents": [
3121
+ {
3122
+ "PR": 866,
3123
+ "Description": "比赛题目页面里左侧栏加入题目序号列表"
3124
+ }
3125
+ ],
3126
+ "Notes": "#860 ..."
3105
3127
  }
3106
3128
  }
3107
3129
  }
package/XMOJ.user.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // ==UserScript==
2
2
  // @name XMOJ
3
- // @version 2.4.2
3
+ // @version 2.4.4
4
4
  // @description XMOJ增强脚本
5
5
  // @author @XMOJ-Script-dev, @langningchen and the community
6
6
  // @namespace https://github/langningchen
@@ -1469,7 +1469,7 @@ async function main() {
1469
1469
  "Name": "恢复讨论与短消息功能"
1470
1470
  }, {
1471
1471
  "ID": "MoreSTD", "Type": "F", "Name": "查看到更多标程"
1472
- }, {"ID": "ApplyData", "Type": "A", "Name": "获取数据功能"}, {
1472
+ }, {
1473
1473
  "ID": "AutoCheat", "Type": "A", "Name": "自动提交当年代码"
1474
1474
  }, {"ID": "Rating", "Type": "A", "Name": "添加用户评分和用户名颜色"}, {
1475
1475
  "ID": "AutoRefresh", "Type": "A", "Name": "比赛列表、比赛排名界面自动刷新"
@@ -1506,6 +1506,8 @@ async function main() {
1506
1506
  }, {
1507
1507
  "ID": "RefreshSolution", "Type": "F", "Name": "状态页面结果自动刷新每次只能刷新一个"
1508
1508
  }, {"ID": "CopyMD", "Type": "A", "Name": "复制题目或题解内容"}, {
1509
+ "ID": "ProblemSwitcher", "Type": "A", "Name": "比赛题目切换器"
1510
+ }, {
1509
1511
  "ID": "OpenAllProblem", "Type": "A", "Name": "比赛题目界面一键打开所有题目"
1510
1512
  }, {
1511
1513
  "ID": "CheckCode", "Type": "A", "Name": "提交代码前对代码进行检查", "Children": [{
@@ -1642,8 +1644,60 @@ async function main() {
1642
1644
  }
1643
1645
  } else if (location.pathname == "/problem.php") {
1644
1646
  await RenderMathJax();
1645
- if (SearchParams.get("cid") != null) {
1647
+ if (SearchParams.get("cid") != null && UtilityEnabled("ProblemSwitcher")) {
1646
1648
  document.getElementsByTagName("h2")[0].innerHTML += " (" + localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID") + ")";
1649
+ let ContestProblemList = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList");
1650
+ if (ContestProblemList == null) {
1651
+ const contestReq = await fetch("https://www.xmoj.tech/contest.php?cid=" + SearchParams.get("cid"));
1652
+ const res = await contestReq.text();
1653
+ if (contestReq.status === 200 && res.indexOf("比赛尚未开始或私有,不能查看题目。") === -1) {
1654
+ const parser = new DOMParser();
1655
+ const dom = parser.parseFromString(res, "text/html");
1656
+ const rows = (dom.querySelector("#problemset > tbody")).rows;
1657
+ let problemList = [];
1658
+ for (let i = 0; i < rows.length; i++) {
1659
+ problemList.push({
1660
+ "title": rows[i].children[2].innerText,
1661
+ "url": rows[i].children[2].children[0].href
1662
+ });
1663
+ }
1664
+ localStorage.setItem("UserScript-Contest-" + SearchParams.get("cid") + "-ProblemList", JSON.stringify(problemList));
1665
+ ContestProblemList = JSON.stringify(problemList);
1666
+ }
1667
+ }
1668
+
1669
+ let problemSwitcher = document.createElement("div");
1670
+ problemSwitcher.style.position = "fixed";
1671
+ problemSwitcher.style.top = "50%";
1672
+ problemSwitcher.style.left = "0";
1673
+ problemSwitcher.style.transform = "translateY(-50%)";
1674
+ problemSwitcher.style.maxHeight = "80vh";
1675
+ problemSwitcher.style.overflowY = "auto";
1676
+ if (document.querySelector("html").getAttribute("data-bs-theme") == "dark") {
1677
+ problemSwitcher.style.backgroundColor = "rgba(0, 0, 0, 0.8)";
1678
+ } else {
1679
+ problemSwitcher.style.backgroundColor = "rgba(255, 255, 255, 0.8)";
1680
+ }
1681
+ problemSwitcher.style.padding = "10px";
1682
+ problemSwitcher.style.borderRadius = "0 10px 10px 0";
1683
+ problemSwitcher.style.display = "flex";
1684
+ problemSwitcher.style.flexDirection = "column";
1685
+
1686
+ let problemList = JSON.parse(ContestProblemList);
1687
+ for (let i = 0; i < problemList.length; i++) {
1688
+ let buttonText = "";
1689
+ if (i < 26) {
1690
+ buttonText = String.fromCharCode(65 + i);
1691
+ } else {
1692
+ buttonText = String.fromCharCode(97 + (i - 26));
1693
+ }
1694
+ let activeClass = "";
1695
+ if (problemList[i].url === location.href) {
1696
+ activeClass = "active";
1697
+ }
1698
+ problemSwitcher.innerHTML += `<a href="${problemList[i].url}" class="btn btn-outline-secondary mb-2 ${activeClass}">${buttonText}</a>`;
1699
+ }
1700
+ document.body.appendChild(problemSwitcher);
1647
1701
  }
1648
1702
  if (document.querySelector("body > div > div.mt-3 > h2") != null) {
1649
1703
  document.querySelector("body > div > div.mt-3").innerHTML = "没有此题目或题目对你不可见";
@@ -3420,121 +3474,6 @@ async function main() {
3420
3474
  if (document.getElementById("apply_data")) {
3421
3475
  let ApplyDiv = document.getElementById("apply_data").parentElement;
3422
3476
  console.log("启动!!!");
3423
- if (UtilityEnabled("ApplyData")) {
3424
- let GetDataButton = document.createElement("button");
3425
- GetDataButton.className = "ms-2 btn btn-outline-secondary";
3426
- GetDataButton.innerText = "获取数据";
3427
- console.log("按钮创建成功");
3428
- ApplyDiv.appendChild(GetDataButton);
3429
- GetDataButton.addEventListener("click", async () => {
3430
- GetDataButton.disabled = true;
3431
- GetDataButton.innerText = "正在获取数据...";
3432
- let PID = localStorage.getItem("UserScript-Solution-" + SearchParams.get("sid") + "-Problem");
3433
- if (PID == null) {
3434
- GetDataButton.innerText = "失败! 无法获取PID";
3435
- GetDataButton.disabled = false;
3436
- await new Promise((resolve) => {
3437
- setTimeout(resolve, 800);
3438
- });
3439
- GetDataButton.innerText = "获取数据";
3440
- return;
3441
- }
3442
- let Code = "";
3443
- if (localStorage.getItem(`UserScript-Problem-${PID}-IOFilename`) !== null) {
3444
- Code = `#define IOFile "${localStorage.getItem(`UserScript-Problem-${PID}-IOFilename`)}"\n`;
3445
- }
3446
- Code += `//XMOJ-Script 获取数据代码
3447
- #include <bits/stdc++.h>
3448
- using namespace std;
3449
- string Base64Encode(string Input)
3450
- {
3451
- const string Base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
3452
- string Output;
3453
- for (int i = 0; i < Input.length(); i += 3)
3454
- {
3455
- Output.push_back(i + 0 > Input.length() ? '=' : Base64Chars[(Input[i + 0] & 0xfc) >> 2]);
3456
- Output.push_back(i + 1 > Input.length() ? '=' : Base64Chars[((Input[i + 0] & 0x03) << 4) + ((Input[i + 1] & 0xf0) >> 4)]);
3457
- Output.push_back(i + 2 > Input.length() ? '=' : Base64Chars[((Input[i + 1] & 0x0f) << 2) + ((Input[i + 2] & 0xc0) >> 6)]);
3458
- Output.push_back(i + 3 > Input.length() ? '=' : Base64Chars[Input[i + 2] & 0x3f]);
3459
- }
3460
- return Output;
3461
- }
3462
- int main()
3463
- {
3464
- #ifdef IOFile
3465
- freopen(IOFile ".in", "r", stdin);
3466
- freopen(IOFile ".out", "w", stdout);
3467
- #endif
3468
- string Input;
3469
- while (1)
3470
- {
3471
- char Data = getchar();
3472
- if (Data == EOF)
3473
- break;
3474
- Input.push_back(Data);
3475
- }
3476
- throw runtime_error("[" + Base64Encode(Input.c_str()) + "]");
3477
- return 0;
3478
- }`;
3479
-
3480
- await fetch("https://www.xmoj.tech/submit.php", {
3481
- "headers": {
3482
- "content-type": "application/x-www-form-urlencoded"
3483
- },
3484
- "referrer": "https://www.xmoj.tech/submitpage.php?id=" + PID,
3485
- "method": "POST",
3486
- "body": "id=" + PID + "&" + "language=1&" + "source=" + encodeURIComponent(Code) + "&" + "enable_O2=on"
3487
- });
3488
-
3489
- let SID = await fetch("https://www.xmoj.tech/status.php").then((Response) => {
3490
- return Response.text();
3491
- }).then((Response) => {
3492
- let ParsedDocument = new DOMParser().parseFromString(Response, "text/html");
3493
- return ParsedDocument.querySelector("#result-tab > tbody > tr:nth-child(1) > td:nth-child(2)").innerText;
3494
- });
3495
-
3496
- await new Promise((Resolve) => {
3497
- let Interval = setInterval(async () => {
3498
- await fetch("status-ajax.php?solution_id=" + SID).then((Response) => {
3499
- return Response.text();
3500
- }).then((Response) => {
3501
- if (Response.split(",")[0] >= 4) {
3502
- clearInterval(Interval);
3503
- Resolve();
3504
- }
3505
- });
3506
- }, 500);
3507
- });
3508
-
3509
- await fetch(`https://www.xmoj.tech/reinfo.php?sid=${SID}`).then((Response) => {
3510
- return Response.text();
3511
- }).then((Response) => {
3512
- let ParsedDocument = new DOMParser().parseFromString(Response, "text/html");
3513
- let ErrorData = ParsedDocument.getElementById("errtxt").innerText;
3514
- let MatchResult = ErrorData.match(/\what\(\): \[([A-Za-z0-9+\/=]+)\]/g);
3515
- if (MatchResult === null) {
3516
- GetDataButton.innerText = "获取数据失败";
3517
- GetDataButton.disabled = false;
3518
- return;
3519
- }
3520
- for (let i = 0; i < MatchResult.length; i++) {
3521
- let Data = CryptoJS.enc.Base64.parse(MatchResult[i].substring(10, MatchResult[i].length - 1)).toString(CryptoJS.enc.Utf8);
3522
- ApplyDiv.appendChild(document.createElement("hr"));
3523
- ApplyDiv.appendChild(document.createTextNode("数据" + (i + 1) + ":"));
3524
- let CodeElement = document.createElement("div");
3525
- ApplyDiv.appendChild(CodeElement);
3526
- CodeMirror(CodeElement, {
3527
- value: Data,
3528
- theme: (UtilityEnabled("DarkMode") ? "darcula" : "default"),
3529
- lineNumbers: true,
3530
- readOnly: true
3531
- }).setSize("100%", "auto");
3532
- }
3533
- GetDataButton.innerText = "获取数据成功";
3534
- GetDataButton.disabled = false;
3535
- });
3536
- });
3537
- }
3538
3477
  document.getElementById("apply_data").addEventListener("click", () => {
3539
3478
  let ApplyElements = document.getElementsByClassName("data");
3540
3479
  for (let i = 0; i < ApplyElements.length; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmoj-script",
3
- "version": "2.4.2",
3
+ "version": "2.4.4",
4
4
  "description": "an improvement script for xmoj.tech",
5
5
  "main": "AddonScript.js",
6
6
  "scripts": {