diff --git a/public/scripts/ui.js b/public/scripts/ui.js index ae63a0e..9cf0b3b 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -2014,10 +2014,19 @@ class ReceiveTextDialog extends Dialog { // Beautify text if text is short if (text.length < 2000) { - // replace urls with actual links - this.$text.innerHTML = this.$text.innerHTML.replace(/((https?:\/\/|www)[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\-._~:\/?#\[\]@!$&'()*+,;=]+)/g, url => { - return `${url}`; - }); + // replace URLs with actual links + this.$text.innerHTML = this.$text.innerHTML + .replace(/(^|(?<=(
|\s)))(https?:\/\/|www.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%]){2,}\.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%.]){2,})/g, + (url) => { + let link = url; + + // prefix www.example.com with http protocol to prevent it from being a relative link + if (link.startsWith('www')) { + link = "http://" + link + } + + return `${url}`; + }); } this._evaluateOverflowing(this.$text); @@ -2048,6 +2057,7 @@ class ReceiveTextDialog extends Dialog { } hide() { + // Todo: clear text field super.hide(); setTimeout(() => this._dequeueRequests(), 500); }