Add one attribute and a simple script to programatically truncate text!
<!-- 💙 MEMBERSCRIPT #18 v0.1 💙 - EASILY TRUNCATE TEXT -->
<script>
// Get all elements with the attribute ms-code-truncate
const elements = document.querySelectorAll('[ms-code-truncate]');
// Loop through each element
elements.forEach((element) => {
// Get the character limit from the attribute
const charLimit = parseInt(element.getAttribute('ms-code-truncate'));
// Get the text content of the element
const text = element.textContent.trim();
// Truncate the text if it exceeds the character limit
if (text.length > charLimit) {
const truncatedText = text.slice(0, charLimit) + '...';
element.textContent = truncatedText;
}
});
</script>