Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Update.json
Original file line number Diff line number Diff line change
Expand Up @@ -2980,6 +2980,17 @@
}
],
"Notes": "No release notes were provided for this release."
},
"2.1.2": {
"UpdateDate": 1755584833374,
"Prerelease": true,
"UpdateContents": [
{
"PR": 833,
"Description": "feat: use credential management api"
}
],
"Notes": "No release notes were provided for this release."
}
}
}
53 changes: 41 additions & 12 deletions XMOJ.user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name XMOJ
// @version 2.1.1
// @version 2.1.2
// @description XMOJ增强脚本
// @author @XMOJ-Script-dev, @langningchen and the community
// @namespace https://github/langningchen
Expand Down Expand Up @@ -441,6 +441,35 @@ let UtilityEnabled = (Name) => {
}
}
};
let storeCredential = async (username, password) => {
if ('credentials' in navigator && window.PasswordCredential) {
try {
const credential = new PasswordCredential({ id: username, password: password });
await navigator.credentials.store(credential);
} catch (e) {
console.error(e);
}
}
};
let getCredential = async () => {
if ('credentials' in navigator && window.PasswordCredential) {
try {
return await navigator.credentials.get({ password: true, mediation: 'optional' });
} catch (e) {
console.error(e);
}
}
return null;
};
let clearCredential = async () => {
if ('credentials' in navigator && window.PasswordCredential) {
try {
await navigator.credentials.preventSilentAccess();
} catch (e) {
console.error(e);
}
}
};
let RequestAPI = (Action, Data, CallBack) => {
try {
let Session = "";
Expand Down Expand Up @@ -962,8 +991,7 @@ async function main() {
location.href = "https://www.xmoj.tech/modifypage.php?ByUserScript=1";
});
PopupUL.children[5].addEventListener("click", () => {
localStorage.removeItem("UserScript-Username");
localStorage.removeItem("UserScript-Password");
clearCredential();
document.cookie = "PHPSESSID=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"; //This is how you remove a cookie?
location.href = "https://www.xmoj.tech/logout.php";
});
Expand Down Expand Up @@ -3217,8 +3245,7 @@ async function main() {
if (UtilityEnabled("LoginFailed")) {
if (Response.indexOf("history.go(-2);") != -1) {
if (UtilityEnabled("SavePassword")) {
localStorage.setItem("UserScript-Username", Username);
localStorage.setItem("UserScript-Password", Password);
await storeCredential(Username, Password);
}
let NewPage = localStorage.getItem("UserScript-LastPage");
if (NewPage == null) {
Expand All @@ -3227,8 +3254,7 @@ async function main() {
location.href = NewPage;
} else {
if (UtilityEnabled("SavePassword")) {
localStorage.removeItem("UserScript-Username");
localStorage.removeItem("UserScript-Password");
clearCredential();
}
Response = Response.substring(Response.indexOf("alert('") + 7);
Response = Response.substring(0, Response.indexOf("');"));
Expand All @@ -3244,10 +3270,13 @@ async function main() {
});
}
});
if (UtilityEnabled("SavePassword") && localStorage.getItem("UserScript-Username") != null && localStorage.getItem("UserScript-Password") != null) {
document.querySelector("#login > div:nth-child(1) > div > input").value = localStorage.getItem("UserScript-Username");
document.querySelector("#login > div:nth-child(2) > div > input").value = localStorage.getItem("UserScript-Password");
LoginButton.click();
if (UtilityEnabled("SavePassword")) {
let Credential = await getCredential();
if (Credential) {
document.querySelector("#login > div:nth-child(1) > div > input").value = Credential.id;
document.querySelector("#login > div:nth-child(2) > div > input").value = Credential.password;
LoginButton.click();
}
}
} else if (location.pathname == "/contest_video.php" || location.pathname == "/problem_video.php") {
let ScriptData = document.querySelector("body > div > div.mt-3 > center > script").innerHTML;
Expand Down Expand Up @@ -3814,7 +3843,7 @@ int main()
AddUser.disabled = true;
RequestAPI("SendMail", {
"ToUser": String(UsernameData),
"Content": String("您好,我是" + localStorage.getItem("UserScript-Username"))
"Content": String("您好,我是" + CurrentUsername)
}, (ResponseData) => {
AddUser.children[0].style.display = "none";
AddUser.disabled = false;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xmoj-script",
"version": "2.1.1",
"version": "2.1.2",
"description": "an improvement script for xmoj.tech",
"main": "AddonScript.js",
"scripts": {
Expand Down