diff --git a/Update.json b/Update.json index 3b3cbb17..72357a37 100644 --- a/Update.json +++ b/Update.json @@ -3032,6 +3032,43 @@ } ], "Notes": "No release notes were provided for this release." + }, + "2.2.2": { + "UpdateDate": 1757851046240, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 852, + "Description": "Fix the submit button on some pages" + } + ], + "Notes": "No release notes were provided for this release." + }, + "2.3.0": { + "UpdateDate": 1757851277491, + "Prerelease": false, + "UpdateContents": [ + { + "PR": 839, + "Description": "Fix formatting in feedback card text" + }, + { + "PR": 852, + "Description": "Fix the submit button on some pages" + } + ], + "Notes": "随着 CI 更新, 相信以后的 release 都会有 release notes(" + }, + "2.3.1": { + "UpdateDate": 1758944205783, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 856, + "Description": "修复由于 PHPSESSID 启用了 httpOnly 导致的后台不可用" + } + ], + "Notes": "本版本修复了由于 PHPSESSID 启用了 httpOnly 导致的后台不可用" } } } \ No newline at end of file diff --git a/XMOJ.user.js b/XMOJ.user.js index 510f5680..563eddf5 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name XMOJ -// @version 2.2.1 +// @version 2.3.1 // @description XMOJ增强脚本 // @author @XMOJ-Script-dev, @langningchen and the community // @namespace https://github/langningchen @@ -20,6 +20,7 @@ // @grant unsafeWindow // @grant GM_setValue // @grant GM_getValue +// @grant GM_cookie // @homepage https://www.xmoj-bbs.me/ // @supportURL https://support.xmoj-bbs.me/form/8050213e-c806-4680-b414-0d1c48263677 // @connect api.xmoj-bbs.tech @@ -444,7 +445,7 @@ let UtilityEnabled = (Name) => { let storeCredential = async (username, password) => { if ('credentials' in navigator && window.PasswordCredential) { try { - const credential = new PasswordCredential({ id: username, password: password }); + const credential = new PasswordCredential({id: username, password: password}); await navigator.credentials.store(credential); } catch (e) { console.error(e); @@ -454,7 +455,7 @@ let storeCredential = async (username, password) => { let getCredential = async () => { if ('credentials' in navigator && window.PasswordCredential) { try { - return await navigator.credentials.get({ password: true, mediation: 'optional' }); + return await navigator.credentials.get({password: true, mediation: 'optional'}); } catch (e) { console.error(e); } @@ -479,6 +480,20 @@ let RequestAPI = (Action, Data, CallBack) => { Session = Temp[i].split("=")[1]; } } + if (Session === "") { //The cookie is httpOnly + GM.cookie.set({ + name: 'PHPSESSID', + value: (Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)).substring(0, 28), + path: "/" + }) + .then(() => { + console.log('Reset PHPSESSID successfully.'); + location.reload(); //Refresh the page to auth with the new PHPSESSID + }) + .catch((error) => { + console.error(error); + }); + } let PostData = { "Authentication": { "SessionID": Session, "Username": CurrentUsername, @@ -1010,7 +1025,17 @@ async function main() { }); PopupUL.children[5].addEventListener("click", () => { clearCredential(); - document.cookie = "PHPSESSID=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"; //This is how you remove a cookie? + GM.cookie.set({ + name: 'PHPSESSID', + value: (Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)).substring(0, 28), + path: "/" + }) + .then(() => { + console.log('Reset PHPSESSID successfully.'); + }) + .catch((error) => { + console.error(error); + }); //We can no longer rely of the server to set the cookie for us location.href = "https://www.xmoj.tech/logout.php"; }); Array.from(PopupUL.children).forEach(item => { @@ -1627,8 +1652,9 @@ async function main() { }, 1000); } else { let PID = localStorage.getItem("UserScript-Contest-" + SearchParams.get("cid") + "-Problem-" + SearchParams.get("pid") + "-PID"); - - document.querySelector("body > div > div.mt-3 > center").lastChild.style.marginLeft = "10px"; + if (document.querySelector("body > div > div.mt-3 > center").lastElementChild !== null) { + document.querySelector("body > div > div.mt-3 > center").lastElementChild.style.marginLeft = "10px"; + } //修复提交按钮 let SubmitLink = document.querySelector('.mt-3 > center:nth-child(1) > a:nth-child(12)'); if (SubmitLink == null) { //a special type of problem diff --git a/package.json b/package.json index 5cd94bd3..9f1ef8ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xmoj-script", - "version": "2.2.1", + "version": "2.3.1", "description": "an improvement script for xmoj.tech", "main": "AddonScript.js", "scripts": {