|
1 | 1 | // ==UserScript== |
2 | 2 | // @name XMOJ |
3 | | -// @version 2.3.0 |
| 3 | +// @version 2.4.0 |
4 | 4 | // @description XMOJ增强脚本 |
5 | 5 | // @author @XMOJ-Script-dev, @langningchen and the community |
6 | 6 | // @namespace https://github/langningchen |
|
20 | 20 | // @grant unsafeWindow |
21 | 21 | // @grant GM_setValue |
22 | 22 | // @grant GM_getValue |
| 23 | +// @grant GM_cookie |
23 | 24 | // @homepage https://www.xmoj-bbs.me/ |
24 | 25 | // @supportURL https://support.xmoj-bbs.me/form/8050213e-c806-4680-b414-0d1c48263677 |
25 | 26 | // @connect api.xmoj-bbs.tech |
@@ -479,6 +480,20 @@ let RequestAPI = (Action, Data, CallBack) => { |
479 | 480 | Session = Temp[i].split("=")[1]; |
480 | 481 | } |
481 | 482 | } |
| 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 | + } |
482 | 497 | let PostData = { |
483 | 498 | "Authentication": { |
484 | 499 | "SessionID": Session, "Username": CurrentUsername, |
@@ -1010,7 +1025,17 @@ async function main() { |
1010 | 1025 | }); |
1011 | 1026 | PopupUL.children[5].addEventListener("click", () => { |
1012 | 1027 | 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 |
1014 | 1039 | location.href = "https://www.xmoj.tech/logout.php"; |
1015 | 1040 | }); |
1016 | 1041 | Array.from(PopupUL.children).forEach(item => { |
|
0 commit comments