phanpy/src/utils/html-content-length.js

12 lines
348 B
JavaScript
Raw Normal View History

const div = document.createElement('div');
2022-12-16 05:27:04 +00:00
export default function htmlContentLength(html) {
2022-12-19 09:30:10 +00:00
if (!html) return 0;
div.innerHTML = html;
2023-12-16 08:05:03 +00:00
// .invisible spans for links
// e.g. <span class="invisible">https://</span>mastodon.social
div.querySelectorAll('.invisible').forEach((el) => {
el.remove();
});
return div.innerText.length;
2022-12-16 05:27:04 +00:00
}