const emotions = ['love', 'thankful', 'happy', 'relief', 'success']; function highlightEmotions() { const elements = document.getElementsByTagName('*'); for(let i = 0; i < elements.length; i++) { const element = elements[i]; for(let j = 0; j < element.childNodes.length; j++) { const node = element.childNodes[j]; if(node.nodeType === 3) { const text = node.nodeValue; const words = text.split(' '); for(let k = 0; k < words.length; k++) { const word = words[k].toLowerCase(); if(emotions.includes(word)) { const newSpan = document.createElement('span'); newSpan.style.backgroundColor = 'yellow'; newSpan.innerText = words[k]; const parent = node.parentNode; parent.replaceChild(newSpan, node); } } } } } } highlightEmotions();
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter