From c76aebda9445a9da79b17fba84fe188a17672f38 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Mon, 28 Dec 2020 16:40:36 +0100 Subject: [PATCH] #147 Fixed parsing and removed console.log --- src/javascript/enhancements/timeConversion.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/javascript/enhancements/timeConversion.js b/src/javascript/enhancements/timeConversion.js index 578038e..58c107d 100644 --- a/src/javascript/enhancements/timeConversion.js +++ b/src/javascript/enhancements/timeConversion.js @@ -7,11 +7,15 @@ export function init() { getGlobalConfiguration().getProperty(SETTINGS_websiteAutoTimeConversion, value => { if (value) { core.runAfterLoad(() => { - updateTimestamps(); + updateTimestamps(document.documentElement); }, ".*"); core.runAfterLocationChange(() => { - updateTimestamps(); + updateTimestamps(document.documentElement); + }, ".*"); + + core.registerScript(node => { + updateTimestamps(node); }, ".*"); } }); @@ -25,8 +29,8 @@ function getSpaceTimeFormat(use24Format) { return '{date}. {month-short} {year} {time}'; } -function updateTimestamps() { - let nodes = helper.findTextNodes(); +function updateTimestamps(node) { + let nodes = helper.findTextNodes(node); nodes.forEach(node => { const REG_DATETIME = /(\d{2}(\/|\.)){2}\d{4} *\d?\d:\d{2}( (AM|PM))?/g; @@ -53,8 +57,6 @@ function updateTimestamps() { timeStr += 'am'; } - console.log(timeStr) - processedStr = processedStr.replace(REG_TIME, timeStr); use24Format = true; } @@ -62,13 +64,10 @@ function updateTimestamps() { // if time has a space before am/pm, this has to be removed for spacetime processedStr = processedStr.replace(REG_AMPM, '$1'); - console.log(processedStr); let datetime = spacetime(processedStr, 'UTC+1', { dmy: true }); datetime = datetime.goto(spacetime().tz); let replaceText = datetime.format(getSpaceTimeFormat(use24Format)); - console.log(replaceText); - - console.log('-------') + node.textContent = node.textContent.replace(hit, replaceText); }) });