mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-23 00:06:18 -04:00
Fix replacement of sent URLs with actual links (fixes #231)
This commit is contained in:
parent
c3e92d7d4c
commit
dd0dc21db5
1 changed files with 14 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue