Add getUsernameFromCookie function

This commit is contained in:
Tristan Schneider 2024-02-19 22:10:17 +01:00
parent 4c904551dc
commit 83231a085d

18
owe.js
View File

@ -55,6 +55,24 @@ async function loadConfig() {
});
}
function getUsernameFromCookie() {
// Split the document.cookie string into individual cookie key-value pairs
var cookies = document.cookie.split(';').map(cookie => cookie.trim());
// Loop through the cookies to find the 'owe_user' cookie
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
if (cookie.startsWith('owe_user=')) {
// Extract the username from the 'owe_user' cookie
return decodeURIComponent(cookie.substring('owe_user='.length));
}
}
// Return null if the 'owe_user' cookie is not set
return null;
}
function onReloadClicked() {
loadSentences();
document.querySelector("#but-reload").style.visibility = "hidden";