mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-23 00:06:18 -04:00
Merge branch 'master' into bring_back_animation
This commit is contained in:
commit
3240921207
8 changed files with 57 additions and 39 deletions
|
@ -81,7 +81,7 @@ class PairDrop {
|
|||
}
|
||||
|
||||
onPwaInstallable(e) {
|
||||
if (!window.matchMedia('(display-mode: minimal-ui)').matches) {
|
||||
if (!window.matchMedia('(display-mode: standalone)').matches) {
|
||||
// only display install btn when not installed
|
||||
this.$headerInstallBtn.removeAttribute('hidden');
|
||||
this.$headerInstallBtn.addEventListener('click', () => {
|
||||
|
|
|
@ -420,7 +420,6 @@ class BackgroundCanvas {
|
|||
w = clientWidth;
|
||||
h = clientHeight;
|
||||
offset = footerOffsetHeight - 28;
|
||||
if (h > 800) offset += 11;
|
||||
|
||||
if (oldW === w && oldH === h && oldOffset === offset) return; // nothing has changed
|
||||
|
||||
|
|
|
@ -2087,35 +2087,48 @@ class ReceiveTextDialog extends Dialog {
|
|||
|
||||
let m = 0;
|
||||
|
||||
const allowedDomainChars = "a-zA-Z0-9áàäčçđéèêŋńñóòôöšŧüžæøåëìíîïðùúýþćěłřśţźǎǐǒǔǥǧǩǯəʒâûœÿãõāēīōūăąĉċďĕėęĝğġģĥħĩĭįıĵķĸĺļľņňŏőŕŗŝşťũŭůűųŵŷżאבגדהוזחטיךכלםמןנסעףפץצקרשתװױײ";
|
||||
const urlRgx = new RegExp(`(^|\\n|\\s|["><\\-_~:\\/?#\\[\\]@!$&'()*+,;=%.])(((https?:\\/\\/)?(?:[${allowedDomainChars}](?:[${allowedDomainChars}-]{0,61}[${allowedDomainChars}])?\\.)+[${allowedDomainChars}][${allowedDomainChars}-]{0,61}[${allowedDomainChars}])(:?\\d*)\\/?([${allowedDomainChars}_\\/\\-#.]*)(\\?([${allowedDomainChars}\\-_~:\\/?#\\[\\]@!$&'()*+,;=%.]*))?)`, 'g');
|
||||
const chrs = `a-zA-Z0-9áàäčçđéèêŋńñóòôöšŧüžæøåëìíîïðùúýþćěłřśţźǎǐǒǔǥǧǩǯəʒâûœÿãõāēīōūăąĉċďĕėęĝğġģĥħĩĭįıĵķĸĺļľņňŏőŕŗŝşťũŭůűųŵŷżאבגדהוזחטיךכלםמןנסעףפץצקרשתװױײ`; // allowed chars in domain names
|
||||
const rgxWhitespace = `(^|\\n|\\s)`;
|
||||
const rgxScheme = `(https?:\\/\\/)`
|
||||
const rgxSchemeMail = `(mailto:)`
|
||||
const rgxUserinfo = `(?:(?:[${chrs}.%]*(?::[${chrs}.%]*)?)@)`;
|
||||
const rgxHost = `(?:(?:[${chrs}](?:[${chrs}-]{0,61}[${chrs}])?\\.)+[${chrs}][${chrs}-]{0,61}[${chrs}])`;
|
||||
const rgxPort = `(:\\d*)`;
|
||||
const rgxPath = `(?:(?:\\/[${chrs}\\-\\._~!$&'\\(\\)\\*\\+,;=:@%]*)*)`;
|
||||
const rgxQueryAndFragment = `(\\?[${chrs}\\-_~:\\/#\\[\\]@!$&'\\(\\)*+,;=%.]*)`;
|
||||
const rgxUrl = `(${rgxScheme}?${rgxHost}${rgxPort}?${rgxPath}${rgxQueryAndFragment}?)`;
|
||||
const rgxMail = `(${rgxSchemeMail}${rgxUserinfo}${rgxHost})`;
|
||||
const rgxUrlAll = new RegExp(`${rgxWhitespace}${rgxUrl}`, 'g');
|
||||
const rgxMailAll = new RegExp(`${rgxWhitespace}${rgxMail}`, 'g');
|
||||
|
||||
$textShadow.innerText = text.replace(urlRgx,
|
||||
(match, whitespaceOrSpecial, url, g3, scheme) => {
|
||||
let link = url;
|
||||
const replaceMatchWithPlaceholder = function(match, whitespace, url, scheme) {
|
||||
let link = url;
|
||||
|
||||
// prefix www.example.com with http protocol to prevent it from being a relative link
|
||||
if (!scheme && link.startsWith('www')) {
|
||||
link = "http://" + link
|
||||
}
|
||||
// prefix www.example.com with http scheme to prevent it from being a relative link
|
||||
if (!scheme && link.startsWith('www')) {
|
||||
link = "http://" + link
|
||||
}
|
||||
|
||||
if (isUrlValid(link)) {
|
||||
// link is valid -> replace with link node placeholder
|
||||
|
||||
// find linkNodePlaceholder that is not yet present in text node
|
||||
m++;
|
||||
while (occP.includes(`${p}${m}`)) {
|
||||
m++;
|
||||
}
|
||||
let linkNodePlaceholder = `${p}${m}`;
|
||||
|
||||
// add linkNodePlaceholder to text node and save a reference to linkNodes object
|
||||
linkNodes[linkNodePlaceholder] = `<a href="${link}" target="_blank" rel="noreferrer">${url}</a>`;
|
||||
return `${whitespaceOrSpecial}${linkNodePlaceholder}`;
|
||||
}
|
||||
if (!isUrlValid(link)) {
|
||||
// link is not valid -> do not replace
|
||||
return match;
|
||||
});
|
||||
}
|
||||
|
||||
// link is valid -> replace with link node placeholder
|
||||
// find linkNodePlaceholder that is not yet present in text node
|
||||
m++;
|
||||
while (occP.includes(`${p}${m}`)) {
|
||||
m++;
|
||||
}
|
||||
let linkNodePlaceholder = `${p}${m}`;
|
||||
|
||||
// add linkNodePlaceholder to text node and save a reference to linkNodes object
|
||||
linkNodes[linkNodePlaceholder] = `<a href="${link}" target="_blank" rel="noreferrer">${url}</a>`;
|
||||
return `${whitespace}${linkNodePlaceholder}`;
|
||||
}
|
||||
|
||||
text = text.replace(rgxUrlAll, replaceMatchWithPlaceholder);
|
||||
$textShadow.innerText = text.replace(rgxMailAll, replaceMatchWithPlaceholder);
|
||||
|
||||
|
||||
this.$text.innerHTML = $textShadow.innerHTML.replace(pRgx,
|
||||
|
|
|
@ -590,7 +590,7 @@ async function decodeBase64Text(base64) {
|
|||
|
||||
function isUrlValid(url) {
|
||||
try {
|
||||
let urlObj = new URL(url);
|
||||
new URL(url);
|
||||
return true;
|
||||
}
|
||||
catch (e) {
|
||||
|
|
|
@ -55,7 +55,6 @@ function initCanvas(footerOffsetHeight, clientWidth, clientHeight) {
|
|||
w = clientWidth;
|
||||
h = clientHeight;
|
||||
offset = footerOffsetHeight - 28;
|
||||
if (h > 800) offset += 11;
|
||||
|
||||
if (oldW === w && oldH === h && oldOffset === offset) return; // nothing has changed
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue