Skip to content

Instantly share code, notes, and snippets.

@attilam
Last active July 8, 2019 06:34
Show Gist options
  • Save attilam/74d5c9f3c6bc66b5e64bb3b28c94e957 to your computer and use it in GitHub Desktop.
Save attilam/74d5c9f3c6bc66b5e64bb3b28c94e957 to your computer and use it in GitHub Desktop.
let spn = document.getElementsByTagName('span')
let t, i, b
let res = ''
for(let s of spn) {
let a = 0
let cn = s.childNodes
while(a < cn.length) {
let node = cn[a]
switch(node.nodeName) {
case '#text':
t = node.textContent
break
case 'I':
i = node.textContent
break
case 'B':
b = node.textContent
t = (t || '').replace(/(\r\n|\n|\r)/gm, ' ').trim()
i = (i || '').replace(/(\r\n|\n|\r)/gm, ' ').trim()
b = (b || '').replace(/(\r\n|\n|\r)/gm, ' ').trim()
if (i === '')
res += `swe: ${t}, eng: ${b}\n`
else
res += `swe: ${t}, grammar: ${i}, eng: ${b}\n`
t = i = b = undefined
break
}
a++
}
}
console.log(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment