Big emojis: fix possible web crash
This commit is contained in:
parent
f208d350a2
commit
a66f2b3f75
1 changed files with 19 additions and 12 deletions
|
@ -2,17 +2,24 @@
|
|||
export const onlyEmoji = (node, limit = 1, ignoreMentions = true) => {
|
||||
if (!node) return false;
|
||||
|
||||
// Remove mentions before checking content
|
||||
if (ignoreMentions) {
|
||||
node = node.cloneNode(true);
|
||||
node.querySelectorAll('a.mention').forEach(m => m.parentNode.removeChild(m));
|
||||
}
|
||||
try {
|
||||
// Remove mentions before checking content
|
||||
if (ignoreMentions) {
|
||||
node = node.cloneNode(true);
|
||||
node.querySelectorAll('a.mention').forEach(m => m.parentNode.removeChild(m));
|
||||
}
|
||||
|
||||
if (node.textContent.replaceAll(' ', '') !== '') return false;
|
||||
const emojis = Array.from(node.querySelectorAll('img.emojione'));
|
||||
if (emojis.length === 0) return false;
|
||||
if (emojis.length > limit) return false;
|
||||
const images = Array.from(node.querySelectorAll('img'));
|
||||
if (images.length > emojis.length) return false;
|
||||
return true;
|
||||
if (node.textContent.replaceAll(' ', '') !== '') return false;
|
||||
const emojis = Array.from(node.querySelectorAll('img.emojione'));
|
||||
if (emojis.length === 0) return false;
|
||||
if (emojis.length > limit) return false;
|
||||
const images = Array.from(node.querySelectorAll('img'));
|
||||
if (images.length > emojis.length) return false;
|
||||
return true;
|
||||
} catch (e) {
|
||||
// Apparently some browsers can't handle `node.textContent.replaceAll`??
|
||||
// If anything in here crashes, skipping it is inconsequential.
|
||||
console.error(e);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue