Improve username setting

This commit is contained in:
Ajay Ramachandran 2020-10-14 23:23:42 -04:00
parent 31d4c621d1
commit ad406d72e4
2 changed files with 21 additions and 24 deletions

View file

@ -196,8 +196,8 @@ div.logoText>p, .sbHeader {
margin-bottom: 12px !important;
}
#mainControls{
flex-flow: column;
align-items: center;
flex-flow: column;
align-items: center;
}
#submitTimesContainer{
flex-flow: column;
@ -216,7 +216,13 @@ align-items: center;
border: none;
color: white;
width: fit-content;
padding: 0;
padding-left: 0;
cursor: pointer;
}
#submitUsername {
padding-left: 5pt;
}
#additionalButtons, #additionalButtons>button {

View file

@ -129,6 +129,7 @@ async function runThePopup(messageListener?: MessageListener) {
PageElements.submitTimes.addEventListener("click", submitTimes);
//PageElements.showNoticeAgain.addEventListener("click", showNoticeAgain);
PageElements.setUsernameButton.addEventListener("click", setUsernameButton);
PageElements.usernameValue.addEventListener("click", setUsernameButton);
PageElements.submitUsername.addEventListener("click", submitUsername);
PageElements.optionsButton.addEventListener("click", openOptions);
PageElements.helpButton.addEventListener("click", openHelp);
@ -834,27 +835,15 @@ async function runThePopup(messageListener?: MessageListener) {
//make the options username setting option visible
function setUsernameButton() {
//get username from the server
utils.sendRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID, function (response) {
if (response.status == 200) {
PageElements.usernameInput.value = JSON.parse(response.responseText).userName;
PageElements.usernameInput.value = PageElements.usernameValue.innerText;
PageElements.submitUsername.style.display = "unset";
PageElements.usernameInput.style.display = "unset";
PageElements.submitUsername.style.display = "unset";
PageElements.usernameInput.style.display = "unset";
PageElements.setUsernameContainer.style.display = "none";
PageElements.setUsername.style.display = "flex";
PageElements
PageElements.setUsernameStatusContainer.style.display = "none";
} else {
PageElements.setUsername.style.display = "unset";
PageElements.submitUsername.style.display = "none";
PageElements.usernameInput.style.display = "none";
PageElements.setUsernameStatusContainer.style.display = "unset";
PageElements.setUsernameStatus.innerText = utils.getErrorMessage(response.status);
}
});
PageElements.setUsernameContainer.style.display = "none";
PageElements.setUsername.style.display = "flex";
PageElements.setUsernameStatusContainer.style.display = "none";
}
//submit the new username
@ -863,14 +852,16 @@ async function runThePopup(messageListener?: MessageListener) {
PageElements.setUsernameStatusContainer.style.display = "unset";
PageElements.setUsernameStatus.innerText = chrome.i18n.getMessage("Loading");
//get the userID
utils.sendRequestToServer("POST", "/api/setUsername?userID=" + Config.config.userID + "&username=" + PageElements.usernameInput.value, function (response) {
if (response.status == 200) {
//submitted
PageElements.submitUsername.style.display = "none";
PageElements.usernameInput.style.display = "none";
PageElements.setUsernameStatus.innerText = chrome.i18n.getMessage("success");
PageElements.setUsernameContainer.style.removeProperty("display");
PageElements.usernameValue.innerText = PageElements.usernameInput.value;
PageElements.setUsernameStatusContainer.style.display = "none";
} else {
PageElements.setUsernameStatus.innerText = utils.getErrorMessage(response.status);
}