From eda430124ef231695b235006705f4e202b87dd3a Mon Sep 17 00:00:00 2001 From: xxchan <xxchan22f@gmail.com> Date: Thu, 7 Apr 2022 21:25:06 +0200 Subject: [PATCH] no need to check dateformat --- index.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 2aba387..ea7d2ee 100644 --- a/index.js +++ b/index.js @@ -1,23 +1,11 @@ -function renderCountdown(el, dateFormat) { +function renderCountdown(el) { // add a countdown to the element // change <time>2022-02-05 Sat</time> to <time>2022-02-05 Sat(x days left)</time> const time = el.querySelector("time") const timeText = time.textContent - const dateFormatParts = dateFormat.split(" ") const timeTextParts = timeText.split(" ") - var timeDate - if (dateFormatParts.length == 1) { - timeDate = moment(timeTextParts[0]).toDate() - } else if (dateFormatParts.length == 2) { - if (dateFormatParts[0][0] == "E") { - timeDate = moment(timeTextParts[1]).toDate() - } else { - timeDate = moment(timeTextParts[0]).toDate() - } - } else { - console.error("Not supported dateFormat: ", dateFormat) - } + const timeDate = moment(timeTextParts[0]).toDate() const now = new Date() const daysDiff = daysDifference(now, timeDate) @@ -34,15 +22,13 @@ async function main() { const pluginId = logseq.baseInfo.id console.info(`#${pluginId}: MAIN`) - const dateFormat = (await logseq.App.getUserConfigs()).preferredDateFormat - const observer = new MutationObserver((mutationList) => { for (const mutation of mutationList) { for (const node of mutation.addedNodes) { if (node.querySelectorAll) { const nodes = node.querySelectorAll(".timestamp") for (const n of nodes) { - renderCountdown(n, dateFormat) + renderCountdown(n) } } }