aboutsummaryrefslogtreecommitdiff
path: root/static/user/user-additions.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/user/user-additions.js')
-rw-r--r--static/user/user-additions.js48
1 files changed, 26 insertions, 22 deletions
diff --git a/static/user/user-additions.js b/static/user/user-additions.js
index 7291f232..3a2951e0 100644
--- a/static/user/user-additions.js
+++ b/static/user/user-additions.js
@@ -1,4 +1,4 @@
-window.formatters.set('description', (el, ev, d) => {
+window.formatters.set('description', async (el, ev, d) => {
if (ev.getProperty('X-MICROSOFT-SKYPETEAMSMEETINGURL')) {
/* parse Microsoft Teams meeting entries */
/* Replace lines with propper <hr> tags */
@@ -32,7 +32,7 @@ window.formatters.set('description', (el, ev, d) => {
idx = match.index + match[0].length
}
children.push(d.substring(idx));
- el.replaceChildren(...children);
+ 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 */
@@ -68,37 +68,41 @@ window.formatters.set('description', (el, ev, d) => {
window.salar = new Promise((resolve, reject) =>
fetch('/static/user/salar.json')
- .then(resp => { if (! resp.ok) reject("404"); else resp.json() })
+ .then(resp => ! resp.ok ? reject("404") : resp.json())
.then(d => resolve(d))
.catch(err => reject(err))
)
-
window.formatters.set('location', async function(el, _, d) {
- let rx = /Lokal: (.*)/
- let m = rx.exec(d)
- if (! m) {
- el.textContent = d;
- return;
- }
+ let salar;
try {
- let salar = await window.salar;
+ salar = await window.salar;
} catch (e) {
console.warn("Location formatter failed", e);
return;
}
- let name = m[1]
- let frag = salar[name];
- if (frag) {
- let anch = document.createElement('a');
- anch.href = `https://old.liu.se/karta/${frag}`
- anch.target = '_blank'
- anch.textContent = name;
- el.append('Lokal: ');
- el.append(anch);
- } else {
- el.textContent = `Lokal: ${name}`
+ let rx = /Lokal: ([A-Za-z0-9]*)?/g
+
+ let idx = 0;
+ let children = []
+ for (let match of d.matchAll(rx)) {
+ children.push(d.substring(idx, match.index))
+ let name = match[1]
+ let frag = salar[name.toUpperCase()];
+ if (frag) {
+ let anch = document.createElement('a');
+ anch.href = `https://old.liu.se/karta/${frag}`
+ anch.target = '_blank'
+ anch.textContent = name;
+ children.push('Lokal: ');
+ children.push(anch);
+ } else {
+ children.push(`Lokal: ${name}`)
+ }
+ idx = match.index + match[0].length
}
+ children.push(d.substring(idx));
+ el.replaceChildren(...children)
})