<script>
document.addEventListener("DOMContentLoaded", function() {
    function linkifyText(node) {
        const urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
        if (node.nodeType === 3) { // Text node
            const text = node.nodeValue;
            const html = text.replace(urlRegex, '<a href="$1" target="_blank">$1</a>');
            if (html !== text) {
                const span = document.createElement('span');
                span.innerHTML = html;
                node.parentNode.replaceChild(span, node);
            }
        } else if (node.nodeType === 1 && node.childNodes && !/^(a|button|textarea)$/i.test(node.tagName)) {
            for (let i = 0; i < node.childNodes.length; i++) {
                linkifyText(node.childNodes[i]);
            }
        }
    }

    linkifyText(document.body);
});
</script>