function fitTitle(el, min = 12, max = 30) { el.style.fontSize = max + 'px'; if (el.scrollWidth <= el.clientWidth) return; let low = min; let high = max; while (low <= high) { const mid = (low + high) >> 1; el.style.fontSize = mid + 'px'; if (el.scrollWidth <= el.clientWidth) { low = mid + 1; } else { high = mid - 1; } } el.style.fontSize = high + 'px'; } function applyFitTitles() { document.querySelectorAll( 'div.item-content div.content-container h3.title a.post-url.post-title' ).forEach(el => fitTitle(el)); } document.fonts.ready.then(applyFitTitles); window.addEventListener('resize', applyFitTitles);