Ag luchtú ábhair...
node => { if (node.nodeType === Node.TEXT_NODE) { let updatedText = node.nodeValue; [ ["mh", "ṁ"], ["bh", "ḃ"], ["ch", "ċ"], ["dh", "ḋ"], ["gh", "ġ"], ["th", "ṫ"], ["fh", "ḟ"], ["ph", "ṗ"], ["sh", "ṡ"], ["Mh", "Ṁ"], ["Bh", "Ḃ"], ["Ch", "Ċ"], ["Dh", "Ḋ"], ["Gh", "Ġ"], ["Th", "Ṫ"], ["Fh", "Ḟ"], ["Ph", "Ṗ"], ["Sh", "Ṡ"] ].forEach(([find, replace]) => { updatedText = updatedText.replaceAll(find, replace); }); // Write the updated text back to the text node node.nodeValue = updatedText; } else if (node.nodeType === Node.ELEMENT_NODE && !(node.tagName.toLowerCase() === 'span' && node.classList.contains('popup-text'))) { // Recursively process non-"popup-text" span child elements replaceAllText2ForElement(node); } }); }; const replaceAllText = () => [["ṁ", "mh"], ["ḃ", "bh"], ["ċ", "ch"], ["ḋ", "dh"], ["ġ", "gh"], ["ṫ", "th"], ["ḟ", "fh"], ["ṗ", "ph"], ["ṡ", "sh"], ["Ṁ", "Mh"], ["Ḃ", "Bh"], ["Ċ", "Ch"], ["Ḋ", "Dh"], ["Ġ", "Gh"], ["Ṫ", "Th"], ["Ḟ", "Fh"], ["Ṗ", "Ph"], ["Ṡ", "Sh"]].forEach(([find, replace]) => findAndReplaceDOMText(document.querySelector('element'), {find, replace }));