mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-21 15:26:17 -04:00
Replace all urls in received messages with links. Center the message if it does not include any whitespace.
This commit is contained in:
parent
d244f5fa47
commit
f9f1abef7a
2 changed files with 30 additions and 22 deletions
|
@ -1,6 +1,5 @@
|
||||||
const $ = query => document.getElementById(query);
|
const $ = query => document.getElementById(query);
|
||||||
const $$ = query => document.body.querySelector(query);
|
const $$ = query => document.body.querySelector(query);
|
||||||
const isURL = text => /^(https?:\/\/|www)[^\s]+$/g.test(text.toLowerCase());
|
|
||||||
window.isProductionEnvironment = !window.location.host.startsWith('localhost');
|
window.isProductionEnvironment = !window.location.host.startsWith('localhost');
|
||||||
window.iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
window.iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
||||||
window.android = /android/i.test(navigator.userAgent);
|
window.android = /android/i.test(navigator.userAgent);
|
||||||
|
@ -1120,16 +1119,21 @@ class ReceiveTextDialog extends Dialog {
|
||||||
_showReceiveTextDialog(text, peerId) {
|
_showReceiveTextDialog(text, peerId) {
|
||||||
this.$displayNameNode.innerText = $(peerId).ui._displayName();
|
this.$displayNameNode.innerText = $(peerId).ui._displayName();
|
||||||
|
|
||||||
if (isURL(text)) {
|
this.$text.innerText = text;
|
||||||
const $a = document.createElement('a');
|
this.$text.classList.remove('text-center');
|
||||||
$a.href = text;
|
|
||||||
$a.target = '_blank';
|
// Beautify text if text is short
|
||||||
$a.textContent = text;
|
if (text.length < 2000) {
|
||||||
this.$text.innerHTML = '';
|
// replace urls with actual links
|
||||||
this.$text.appendChild($a);
|
this.$text.innerHTML = this.$text.innerHTML.replace(/((https?:\/\/|www)[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\-._~:\/?#\[\]@!$&'()*+,;=]+)/g, url => {
|
||||||
} else {
|
return `<a href="${url}" target="_blank">${url}</a>`;
|
||||||
this.$text.textContent = text;
|
});
|
||||||
|
|
||||||
|
if (!/\s/.test(text)) {
|
||||||
|
this.$text.classList.add('text-center');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._setDocumentTitleMessages();
|
this._setDocumentTitleMessages();
|
||||||
|
|
||||||
document.changeFavicon("images/favicon-96x96-notification.png");
|
document.changeFavicon("images/favicon-96x96-notification.png");
|
||||||
|
@ -1359,7 +1363,7 @@ class Notifications {
|
||||||
_messageNotification(message, peerId) {
|
_messageNotification(message, peerId) {
|
||||||
if (document.visibilityState !== 'visible') {
|
if (document.visibilityState !== 'visible') {
|
||||||
const peerDisplayName = $(peerId).ui._displayName();
|
const peerDisplayName = $(peerId).ui._displayName();
|
||||||
if (isURL(message)) {
|
if (/^((https?:\/\/|www)[abcdefghijklmnopqrstuvwxyz0123456789\-._~:\/?#\[\]@!$&'()*+,;=]+)$/.test(message.toLowerCase())) {
|
||||||
const notification = this._notify(`Link received by ${peerDisplayName} - Click to open`, message);
|
const notification = this._notify(`Link received by ${peerDisplayName} - Click to open`, message);
|
||||||
this._bind(notification, _ => window.open(message, '_blank', null, true));
|
this._bind(notification, _ => window.open(message, '_blank', null, true));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
const $ = query => document.getElementById(query);
|
const $ = query => document.getElementById(query);
|
||||||
const $$ = query => document.body.querySelector(query);
|
const $$ = query => document.body.querySelector(query);
|
||||||
const isURL = text => /^(https?:\/\/|www)[^\s]+$/g.test(text.toLowerCase());
|
|
||||||
window.isProductionEnvironment = !window.location.host.startsWith('localhost');
|
window.isProductionEnvironment = !window.location.host.startsWith('localhost');
|
||||||
window.iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
window.iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
||||||
window.android = /android/i.test(navigator.userAgent);
|
window.android = /android/i.test(navigator.userAgent);
|
||||||
|
@ -1121,16 +1120,21 @@ class ReceiveTextDialog extends Dialog {
|
||||||
_showReceiveTextDialog(text, peerId) {
|
_showReceiveTextDialog(text, peerId) {
|
||||||
this.$displayNameNode.innerText = $(peerId).ui._displayName();
|
this.$displayNameNode.innerText = $(peerId).ui._displayName();
|
||||||
|
|
||||||
if (isURL(text)) {
|
this.$text.innerText = text;
|
||||||
const $a = document.createElement('a');
|
this.$text.classList.remove('text-center');
|
||||||
$a.href = text;
|
|
||||||
$a.target = '_blank';
|
// Beautify text if text is short
|
||||||
$a.textContent = text;
|
if (text.length < 2000) {
|
||||||
this.$text.innerHTML = '';
|
// replace urls with actual links
|
||||||
this.$text.appendChild($a);
|
this.$text.innerHTML = this.$text.innerHTML.replace(/((https?:\/\/|www)[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\-._~:\/?#\[\]@!$&'()*+,;=]+)/g, url => {
|
||||||
} else {
|
return `<a href="${url}" target="_blank">${url}</a>`;
|
||||||
this.$text.textContent = text;
|
});
|
||||||
|
|
||||||
|
if (!/\s/.test(text)) {
|
||||||
|
this.$text.classList.add('text-center');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._setDocumentTitleMessages();
|
this._setDocumentTitleMessages();
|
||||||
|
|
||||||
document.changeFavicon("images/favicon-96x96-notification.png");
|
document.changeFavicon("images/favicon-96x96-notification.png");
|
||||||
|
@ -1360,7 +1364,7 @@ class Notifications {
|
||||||
_messageNotification(message, peerId) {
|
_messageNotification(message, peerId) {
|
||||||
if (document.visibilityState !== 'visible') {
|
if (document.visibilityState !== 'visible') {
|
||||||
const peerDisplayName = $(peerId).ui._displayName();
|
const peerDisplayName = $(peerId).ui._displayName();
|
||||||
if (isURL(message)) {
|
if (/^((https?:\/\/|www)[abcdefghijklmnopqrstuvwxyz0123456789\-._~:\/?#\[\]@!$&'()*+,;=]+)$/.test(message.toLowerCase())) {
|
||||||
const notification = this._notify(`Link received by ${peerDisplayName} - Click to open`, message);
|
const notification = this._notify(`Link received by ${peerDisplayName} - Click to open`, message);
|
||||||
this._bind(notification, _ => window.open(message, '_blank', null, true));
|
this._bind(notification, _ => window.open(message, '_blank', null, true));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue