jschan - Anonymous imageboard software. Classic look, modern features and feel. Works without JavaScript and supports Tor, I2P, Lokinet, etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

36 lines
992 B

window.addEventListener('DOMContentLoaded', () => {
const messageBox = document.getElementById('message');
if (messageBox) {
const messageBoxLabel = messageBox.previousSibling;
const maxLength = messageBox.getAttribute('maxlength');
const minLength = messageBox.getAttribute('minlength');
let currentLength = messageBox.value.length;
const counter = document.createElement('small');
messageBoxLabel.appendChild(counter);
const updateCounter = () => {
counter.innerText = `(${currentLength}/${maxLength})`;
if (currentLength >= maxLength || currentLength < minLength) {
counter.style.color = 'red';
} else {
counter.removeAttribute('style');
}
};
const updateLength = function() {
if (messageBox.value.length > maxLength) {
messageBox.value = messageBox.value.substring(0,maxLength);
}
currentLength = messageBox.value.length;
updateCounter();
};
updateCounter();
messageBox.addEventListener('input', updateLength);
}
});