Skip to content

Commit f818349

Browse files
Merge pull request #853 from XMOJ-Script-dev/dev
sync: dev to extern-contrib
2 parents b2e8af6 + 85bf70a commit f818349

3 files changed

Lines changed: 70 additions & 7 deletions

File tree

Update.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,6 +3032,43 @@
30323032
}
30333033
],
30343034
"Notes": "No release notes were provided for this release."
3035+
},
3036+
"2.2.2": {
3037+
"UpdateDate": 1757851046240,
3038+
"Prerelease": true,
3039+
"UpdateContents": [
3040+
{
3041+
"PR": 852,
3042+
"Description": "Fix the submit button on some pages"
3043+
}
3044+
],
3045+
"Notes": "No release notes were provided for this release."
3046+
},
3047+
"2.3.0": {
3048+
"UpdateDate": 1757851277491,
3049+
"Prerelease": false,
3050+
"UpdateContents": [
3051+
{
3052+
"PR": 839,
3053+
"Description": "Fix formatting in feedback card text"
3054+
},
3055+
{
3056+
"PR": 852,
3057+
"Description": "Fix the submit button on some pages"
3058+
}
3059+
],
3060+
"Notes": "随着 CI 更新, 相信以后的 release 都会有 release notes("
3061+
},
3062+
"2.3.1": {
3063+
"UpdateDate": 1758944205783,
3064+
"Prerelease": true,
3065+
"UpdateContents": [
3066+
{
3067+
"PR": 856,
3068+
"Description": "修复由于 PHPSESSID 启用了 httpOnly 导致的后台不可用"
3069+
}
3070+
],
3071+
"Notes": "本版本修复了由于 PHPSESSID 启用了 httpOnly 导致的后台不可用"
30353072
}
30363073
}
30373074
}

XMOJ.user.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name XMOJ
3-
// @version 2.2.1
3+
// @version 2.3.1
44
// @description XMOJ增强脚本
55
// @author @XMOJ-Script-dev, @langningchen and the community
66
// @namespace https://github/langningchen
@@ -20,6 +20,7 @@
2020
// @grant unsafeWindow
2121
// @grant GM_setValue
2222
// @grant GM_getValue
23+
// @grant GM_cookie
2324
// @homepage https://www.xmoj-bbs.me/
2425
// @supportURL https://support.xmoj-bbs.me/form/8050213e-c806-4680-b414-0d1c48263677
2526
// @connect api.xmoj-bbs.tech
@@ -444,7 +445,7 @@ let UtilityEnabled = (Name) => {
444445
let storeCredential = async (username, password) => {
445446
if ('credentials' in navigator && window.PasswordCredential) {
446447
try {
447-
const credential = new PasswordCredential({ id: username, password: password });
448+
const credential = new PasswordCredential({id: username, password: password});
448449
await navigator.credentials.store(credential);
449450
} catch (e) {
450451
console.error(e);
@@ -454,7 +455,7 @@ let storeCredential = async (username, password) => {
454455
let getCredential = async () => {
455456
if ('credentials' in navigator && window.PasswordCredential) {
456457
try {
457-
return await navigator.credentials.get({ password: true, mediation: 'optional' });
458+
return await navigator.credentials.get({password: true, mediation: 'optional'});
458459
} catch (e) {
459460
console.error(e);
460461
}
@@ -479,6 +480,20 @@ let RequestAPI = (Action, Data, CallBack) => {
479480
Session = Temp[i].split("=")[1];
480481
}
481482
}
483+
if (Session === "") { //The cookie is httpOnly
484+
GM.cookie.set({
485+
name: 'PHPSESSID',
486+
value: (Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)).substring(0, 28),
487+
path: "/"
488+
})
489+
.then(() => {
490+
console.log('Reset PHPSESSID successfully.');
491+
location.reload(); //Refresh the page to auth with the new PHPSESSID
492+
})
493+
.catch((error) => {
494+
console.error(error);
495+
});
496+
}
482497
let PostData = {
483498
"Authentication": {
484499
"SessionID": Session, "Username": CurrentUsername,
@@ -1010,7 +1025,17 @@ async function main() {
10101025
});
10111026
PopupUL.children[5].addEventListener("click", () => {
10121027
clearCredential();
1013-
document.cookie = "PHPSESSID=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"; //This is how you remove a cookie?
1028+
GM.cookie.set({
1029+
name: 'PHPSESSID',
1030+
value: (Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)).substring(0, 28),
1031+
path: "/"
1032+
})
1033+
.then(() => {
1034+
console.log('Reset PHPSESSID successfully.');
1035+
})
1036+
.catch((error) => {
1037+
console.error(error);
1038+
}); //We can no longer rely of the server to set the cookie for us
10141039
location.href = "https://www.xmoj.tech/logout.php";
10151040
});
10161041
Array.from(PopupUL.children).forEach(item => {
@@ -1627,8 +1652,9 @@ async function main() {
16271652
}, 1000);
16281653
} else {
16291654
let PID = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID");
1630-
1631-
document.querySelector("body > div > div.mt-3 > center").lastChild.style.marginLeft = "10px";
1655+
if (document.querySelector("body > div > div.mt-3 > center").lastElementChild !== null) {
1656+
document.querySelector("body > div > div.mt-3 > center").lastElementChild.style.marginLeft = "10px";
1657+
}
16321658
//修复提交按钮
16331659
let SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(12)');
16341660
if (SubmitLink == null) { //a special type of problem

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xmoj-script",
3-
"version": "2.2.1",
3+
"version": "2.3.1",
44
"description": "an improvement script for xmoj.tech",
55
"main": "AddonScript.js",
66
"scripts": {

0 commit comments

Comments
 (0)