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:
@@ -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 |
|
||||
| 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 |
|
||||
| message | string | Not in config by default | Static custom message |
|
||||
| disableDate | \<false \| true\> | false | Hide the date |
|
||||
| disableSearchBar | \<false \| true\> | false | Hide the search bar |
|
||||
| disable24Hour | \<false \| true\> | true | Disable 24 hour clock and show time in 12 hour format |
|
||||
|
||||
26
js/main.js
26
js/main.js
@@ -125,6 +125,20 @@ function buildMsg() {
|
||||
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() {
|
||||
/**
|
||||
* Get the current time and date and return it.
|
||||
@@ -197,10 +211,14 @@ function parseAndCreate(jsonData) {
|
||||
*/
|
||||
this.userName = jsonData["user"]
|
||||
|
||||
// Build a message for the user
|
||||
builtMsg = buildMsg()
|
||||
builtMsg == "" ?
|
||||
builtMsg = `Hello ${this.userName}` : builtMsg = `Hey ${this.userName}, ${builtMsg}!`
|
||||
// If the user has not passed any custom message
|
||||
if (Object.keys(jsonData).includes("message") &&
|
||||
typeof(jsonData["message"]) == "string" &&
|
||||
jsonData["message"] != "")
|
||||
builtMsg = jsonData["message"]
|
||||
else
|
||||
builtMsg = this.handleMessage(this.userName);
|
||||
|
||||
document.getElementById(messageId).textContent = builtMsg
|
||||
// Check if 24 hour is disabled
|
||||
disable24Hour = jsonData["disable24Hour"]
|
||||
|
||||
Reference in New Issue
Block a user