-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
45 lines (36 loc) · 1.22 KB
/
script.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
35
36
37
38
39
40
41
42
43
44
45
window.onload = () => {
const input = document.getElementById("input")
const output = document.getElementById("output")
const tmpContainer = document.getElementById("tmp-container")
let keyTimer = null
input.addEventListener("keyup", function () {
clearTimeout(keyTimer);
keyTimer = setTimeout(convertText, 300)
})
function emptyContainers() {
tmpContainer.innerHTML = ''
output.placeholder = ''
output.value = ''
}
function convertText() {
if (input.value === '') {
emptyContainers()
return
}
tmpContainer.innerHTML = input.value
const links = document.querySelectorAll("#tmp-container a")
const contents = Array.from(links).map(link => {
return link.innerHTML
})
if (contents.length < 1) {
emptyContainers()
output.placeholder = 'Изначальный текст в неверном формате.'
return
}
output.placeholder = ''
output.value = contents.reduce((previousValue, currentValue) => {
return `${previousValue}\n${currentValue}`
})
tmpContainer.innerHTML = ''
}
}