bigbuffet-rw/app/soapbox/utils/rich_content.js

12 lines
486 B
JavaScript
Raw Normal View History

2021-07-09 12:22:01 -07:00
// Returns `true` if the node contains only emojis, up to a limit
2021-07-09 14:51:47 -07:00
export const onlyEmoji = (node, limit = 1) => {
2021-07-09 12:22:01 -07:00
if (!node) return false;
if (node.textContent.replaceAll(' ', '') !== '') return false;
2021-07-09 15:02:04 -07:00
const emojis = Array.from(node.querySelectorAll('img.emojione'));
2021-07-09 14:51:47 -07:00
if (emojis.length === 0) return false;
2021-07-09 12:22:01 -07:00
if (emojis.length > limit) return false;
2021-07-09 15:02:04 -07:00
const images = Array.from(node.querySelectorAll('img'));
2021-07-09 12:22:01 -07:00
if (images.length > emojis.length) return false;
return true;
};