add URL git username param (#2)

* add URL git username param

* Update src/script.js

---------

Co-authored-by: Marcus Noble <AverageMarcus@users.noreply.github.com>
This commit is contained in:
saifeddine Rajhi 2024-03-03 11:37:54 +01:00 committed by GitHub
parent 2a0bfb6add
commit e9fd8681ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,16 @@ const status = document.querySelector("#status");
const rawResultsWrapper = document.querySelector("#rawResultsWrapper");
const rawResults = document.querySelector("#rawResults");
// Parse URL query parameters
const urlParams = new URLSearchParams(window.location.search);
const user = urlParams.get('user');
// Fill form with user parameter
if (user) {
gh.value = user;
find(); // Call the find function automatically
}
function find() {
let user = gh.value.toLowerCase();
if (user != "") {
@ -37,6 +47,12 @@ function find() {
statusUpdate(`Failed to get devstats score for '${user}'`, "error");
console.log(err);
});
// Change the URL
let url = new URL(window.location.href);
let params = new URLSearchParams(url.search);
params.set('user', user);
window.history.replaceState({}, '', `${url.pathname}?${params}`);
}
}