From 2185a0a031e9fca82dfb554c2ece864d1efb9fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 7 Jul 2022 21:13:31 +0200 Subject: JS user addition for parsing Microsoft Teams links. --- static/user/user-additions.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/static/user/user-additions.js b/static/user/user-additions.js index 5f5357eb..7291f232 100644 --- a/static/user/user-additions.js +++ b/static/user/user-additions.js @@ -1,5 +1,39 @@ window.formatters.set('description', (el, ev, d) => { - if (/<\/?\w+( +\w+(=["']?\w+["']?)?)* *\/?>/.exec(d)) { + if (ev.getProperty('X-MICROSOFT-SKYPETEAMSMEETINGURL')) { + /* parse Microsoft Teams meeting entries */ + /* Replace lines with propper
tags */ + let rx1 = /^_+$/gm + /* Merge URL:s into a tags */ + let rx2 = /(?^|[|])\s*(?[^|<\n]*)<(?[^>]*)>/gm + + let rxs = [`(?${rx1.source})`, + `(?${rx2.source})`, + ].join('|') + let rx = new RegExp(`(${rxs})`, 'gm') + + let children = [] + let idx = 0 + for (let match of d.matchAll(rx)) { + children.push(d.substring(idx, match.index)) + + if (match.groups.line) { + children.push(document.createElement('hr')) + children.push(document.createElement('br')) + } else if (match.groups.link) { + if (match.groups.pipe === '|') { + children.push('| '); + } + let a = document.createElement('a') + a.textContent = match.groups.name || match.groups.url + a.href = match.groups.url + children.push(a) + } + + idx = match.index + match[0].length + } + children.push(d.substring(idx)); + el.replaceChildren(...children); + } else if (/<\/?\w+( +\w+(=["']?\w+["']?)?)* *\/?>/.exec(d)) { /* Assume that the text is HTML if it contains something which looks like an HTML tag */ let parser = new DOMParser(); -- cgit v1.2.3