Fixed some bugs related to username.

This commit is contained in:
deepjyoti30
2020-05-12 23:26:10 +05:30
parent 8f12751c89
commit 4fc71fd0f6

View File

@@ -22,6 +22,10 @@ function initBody() {
*/
// Clear the search bar on load, just in case
document.getElementById(searchBarId).value = ""
// Read the json file
json = readJSON("config.json")
document.getElementById(searchBarId).addEventListener("keypress", (event) => {
if (event.key != 'Enter') return
@@ -30,15 +34,6 @@ function initBody() {
query = document.getElementById(searchBarId).value.replace(/\ /g, "+")
document.location = googleSearchUrl + query
})
// Build a message for the user
builtMsg = buildMsg()
builtMsg == "" ?
builtMsg = `Hello ${userName}` : builtMsg = `Hey ${userName}, ${builtMsg}!`
document.getElementById(messageId).textContent = builtMsg
// Read the json file
json = readJSON("config.json")
}
function buildMsg() {
@@ -92,6 +87,14 @@ function parseAndCreate(jsonData) {
* Parse the passed jsonData and create div's accordingly.
*/
this.userName = jsonData["user"]
// Build a message for the user
builtMsg = buildMsg()
builtMsg == "" ?
builtMsg = `Hello ${this.userName}` : builtMsg = `Hey ${this.userName}, ${builtMsg}!`
document.getElementById(messageId).textContent = builtMsg
sqrs = jsonData["squares"]
sqrs.forEach((element, index) => {