phanpy/src/utils/html-content-length.js
2023-12-17 18:25:58 +08:00

11 lines
348 B
JavaScript

const div = document.createElement('div');
export default function htmlContentLength(html) {
if (!html) return 0;
div.innerHTML = html;
// .invisible spans for links
// e.g. <span class="invisible">https://</span>mastodon.social
div.querySelectorAll('.invisible').forEach((el) => {
el.remove();
});
return div.innerText.length;
}