-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (31 loc) · 963 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function translate(text) {
return text
.replaceAll('aa', 'å')
.replaceAll('oe', 'ø')
.replaceAll('ae', 'æ')
.replaceAll('Aa', 'Å')
.replaceAll('Oe', 'Ø')
.replaceAll('Ae', 'Æ');
};
function correct(text) {
return text
.replace(/(i)sræl/gi, '$1srael')
.replace(/(r)isikøn/gi, '$1isikoen');
};
function update(input , output) {
return () => {
const urls = /(https?:\/\/[^\s]+)/g;
const cuts = input.value.split(urls).filter(Boolean);
const fixt = cuts.map((cut, i) => urls.test(cut) ? cut : translate(cut));
output.value = correct(fixt.join('').trim());
}
}
addEventListener('DOMContentLoaded', () => {
const input = document.querySelector('#input');
const output = document.querySelector('#output');
output.addEventListener('focus', () => output.select());
const refresh = update(input, output);
addEventListener('keyup', refresh);
addEventListener('input', refresh);
refresh();
});