#147 Fixed parsing and removed console.log

This commit is contained in:
Serraniel 2020-12-28 16:40:36 +01:00
parent 5fcaca8b54
commit c76aebda94
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -7,11 +7,15 @@ export function init() {
getGlobalConfiguration().getProperty(SETTINGS_websiteAutoTimeConversion, value => { getGlobalConfiguration().getProperty(SETTINGS_websiteAutoTimeConversion, value => {
if (value) { if (value) {
core.runAfterLoad(() => { core.runAfterLoad(() => {
updateTimestamps(); updateTimestamps(document.documentElement);
}, ".*"); }, ".*");
core.runAfterLocationChange(() => { core.runAfterLocationChange(() => {
updateTimestamps(); updateTimestamps(document.documentElement);
}, ".*");
core.registerScript(node => {
updateTimestamps(node);
}, ".*"); }, ".*");
} }
}); });
@ -25,8 +29,8 @@ function getSpaceTimeFormat(use24Format) {
return '{date}. {month-short} {year} {time}'; return '{date}. {month-short} {year} {time}';
} }
function updateTimestamps() { function updateTimestamps(node) {
let nodes = helper.findTextNodes(); let nodes = helper.findTextNodes(node);
nodes.forEach(node => { nodes.forEach(node => {
const REG_DATETIME = /(\d{2}(\/|\.)){2}\d{4} *\d?\d:\d{2}( (AM|PM))?/g; const REG_DATETIME = /(\d{2}(\/|\.)){2}\d{4} *\d?\d:\d{2}( (AM|PM))?/g;
@ -53,8 +57,6 @@ function updateTimestamps() {
timeStr += 'am'; timeStr += 'am';
} }
console.log(timeStr)
processedStr = processedStr.replace(REG_TIME, timeStr); processedStr = processedStr.replace(REG_TIME, timeStr);
use24Format = true; use24Format = true;
} }
@ -62,13 +64,10 @@ function updateTimestamps() {
// if time has a space before am/pm, this has to be removed for spacetime // if time has a space before am/pm, this has to be removed for spacetime
processedStr = processedStr.replace(REG_AMPM, '$1'); processedStr = processedStr.replace(REG_AMPM, '$1');
console.log(processedStr);
let datetime = spacetime(processedStr, 'UTC+1', { dmy: true }); let datetime = spacetime(processedStr, 'UTC+1', { dmy: true });
datetime = datetime.goto(spacetime().tz); datetime = datetime.goto(spacetime().tz);
let replaceText = datetime.format(getSpaceTimeFormat(use24Format)); let replaceText = datetime.format(getSpaceTimeFormat(use24Format));
console.log(replaceText);
console.log('-------')
node.textContent = node.textContent.replace(hit, replaceText); node.textContent = node.textContent.replace(hit, replaceText);
}) })
}); });