From e9fd8681ac15d68b1b7b84eb8a0da97c6ed9bdd1 Mon Sep 17 00:00:00 2001 From: saifeddine Rajhi Date: Sun, 3 Mar 2024 11:37:54 +0100 Subject: [PATCH] add URL git username param (#2) * add URL git username param * Update src/script.js --------- Co-authored-by: Marcus Noble --- src/script.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/script.js b/src/script.js index 85e3173..914255d 100644 --- a/src/script.js +++ b/src/script.js @@ -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}`); } }