Fix replacement of sent URLs with actual links (fixes #231)

This commit is contained in:
schlagmichdoch 2024-01-03 13:54:13 +01:00
parent c3e92d7d4c
commit dd0dc21db5

View file

@ -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 `<a href="${url}" target="_blank">${url}</a>`;
});
// replace URLs with actual links
this.$text.innerHTML = this.$text.innerHTML
.replace(/(^|(?<=(<br>|\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 `<a href="${link}" target="_blank">${url}</a>`;
});
}
this._evaluateOverflowing(this.$text);
@ -2048,6 +2057,7 @@ class ReceiveTextDialog extends Dialog {
}
hide() {
// Todo: clear text field
super.hide();
setTimeout(() => this._dequeueRequests(), 500);
}