Add a new field message to config.json

The greeting message can now be set to a custom static message.

The field in the config required is `message` and it needs to be a
string. If the string is not empty, it will be shown instead of the
default greet message.

In order to disbale it, the field needs to be omitted or set to an empty
string like `""`.
This commit is contained in:
deepjyoti30
2020-08-10 15:56:25 +05:30
parent aaf8b63af6
commit 0e83664295
2 changed files with 23 additions and 4 deletions

View File

@@ -50,6 +50,7 @@ A JSON editor will open up where you can make the changes.
| searchEngine | \<DuckDuckGo \| Google \| Bing \|Yahoo\> | DuckDuckGo | Search Engine to use for searching from the bar | | searchEngine | \<DuckDuckGo \| Google \| Bing \|Yahoo\> | DuckDuckGo | Search Engine to use for searching from the bar |
| user | string | Deepjyoti (That's my name) | Name of the user to use on the welcome message | | user | string | Deepjyoti (That's my name) | Name of the user to use on the welcome message |
| disableMessage | \<false \| true\> | false | Hide the Welcome message | | disableMessage | \<false \| true\> | false | Hide the Welcome message |
| message | string | Not in config by default | Static custom message |
| disableDate | \<false \| true\> | false | Hide the date | | disableDate | \<false \| true\> | false | Hide the date |
| disableSearchBar | \<false \| true\> | false | Hide the search bar | | disableSearchBar | \<false \| true\> | false | Hide the search bar |
| disable24Hour | \<false \| true\> | true | Disable 24 hour clock and show time in 12 hour format | | disable24Hour | \<false \| true\> | true | Disable 24 hour clock and show time in 12 hour format |

View File

@@ -125,6 +125,20 @@ function buildMsg() {
return "" return ""
} }
function handleMessage(userName) {
/**
* Handle the creation of the message
*
* Build the message based on the time of the day.
* If the message is null then add just the username
* Else, add the username before the message.
*/
var builtMsg = buildMsg()
builtMsg == "" ?
builtMsg = `Hello ${userName}` : builtMsg = `Hey ${userName}, ${builtMsg}!`
return builtMsg;
}
function updateTime() { function updateTime() {
/** /**
* Get the current time and date and return it. * Get the current time and date and return it.
@@ -197,10 +211,14 @@ function parseAndCreate(jsonData) {
*/ */
this.userName = jsonData["user"] this.userName = jsonData["user"]
// Build a message for the user // If the user has not passed any custom message
builtMsg = buildMsg() if (Object.keys(jsonData).includes("message") &&
builtMsg == "" ? typeof(jsonData["message"]) == "string" &&
builtMsg = `Hello ${this.userName}` : builtMsg = `Hey ${this.userName}, ${builtMsg}!` jsonData["message"] != "")
builtMsg = jsonData["message"]
else
builtMsg = this.handleMessage(this.userName);
document.getElementById(messageId).textContent = builtMsg document.getElementById(messageId).textContent = builtMsg
// Check if 24 hour is disabled // Check if 24 hour is disabled
disable24Hour = jsonData["disable24Hour"] disable24Hour = jsonData["disable24Hour"]