From 3753549a85a7f47e50f726f68d610ae964836043 Mon Sep 17 00:00:00 2001 From: Haider Ali Punjabi Date: Thu, 14 May 2020 15:34:41 +0530 Subject: [PATCH] Improved update time code, and added option to disable 24 hour --- config.json | 3 ++- js/main.js | 26 +++++--------------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/config.json b/config.json index ae6d363..fbc1019 100644 --- a/config.json +++ b/config.json @@ -33,5 +33,6 @@ "user": "Deepjyoti", "disableMessage": false, "disableDate": false, - "disableSearchBar": false + "disableSearchBar": false, + "disable24Hour": false } diff --git a/js/main.js b/js/main.js index e5fa33d..ceebbd6 100644 --- a/js/main.js +++ b/js/main.js @@ -10,6 +10,7 @@ dateId = "date-text" messageId = "message-text" otherContentId = "other-content" userName = "Deepjyoti" +disable24Hour = false; bgClassContainer = [ "media", "work", @@ -21,21 +22,6 @@ bgClassContainer = [ "indigo", "foxxy" ] -dateMap = { - 0: "Jan", - 1: "Feb", - 2: "Mar", - 3: "Apr", - 4: "May", - 5: "Jun", - 6: "Jul", - 7: "Aug", - 8: "Sep", - 9: "Oct", - 10: "Nov", - 11: "Dec" -} - searchEngines = { "Google": "https://www.google.com/search?q=", "DuckDuckGo": "https://duckduckgo.com/?q=", @@ -111,11 +97,7 @@ function updateTime() { * Get the current time and date and return it. */ currentDate = new Date() - date = currentDate.getDate() - month = dateMap[currentDate.getMonth()] - minutes = currentDate.getMinutes() - time = currentDate.getHours() + ":" + (minutes < 10 ? "0" + minutes : minutes) - finalDate = date + " " + month + ", " + time + finalDate = currentDate.toLocaleString(undefined, {day:'numeric', month:'short', hour:'numeric', minute:'numeric',hour12:disable24Hour}) document.getElementById(dateId).textContent = finalDate } @@ -150,7 +132,8 @@ function parseAndCreate(jsonData) { builtMsg == "" ? builtMsg = `Hello ${this.userName}` : builtMsg = `Hey ${this.userName}, ${builtMsg}!` document.getElementById(messageId).textContent = builtMsg - + // Check if 24 hour is disabled + disable24Hour = jsonData["disable24Hour"] // Check if welcome message is supposed to be disabled if (jsonData["disableMessage"]) document.getElementById(messageDivId).style.display = "none" @@ -170,6 +153,7 @@ function parseAndCreate(jsonData) { sqr = createSqr(element, index) document.getElementById(otherContentId).appendChild(sqr) }) + } function createSqr(sqrData, index) {