Messages for Web Character Count

Google's Android Messages for Web is fantastic, but it lacks one key feature: showing a character count. The app version does this; I'm not sure why it was omitted from the website. For users who want to know if they'll be sending an SMS or MMS (typically used for longer messages), this can be a problem. So I wrote a script that automatically adds a character count under the send button.


Screenshots


Installation

Userscript

You can install this userscript using a browser extension like Tampermonkey.
Download


Bookmarklet

Alternately, you can make a bookmark with the following script as the URL and click it when desired.

javascript:
const CHAR_LIMIT=765;
const RED_BACKGROUND=true;
setInterval(checkLength,100);function checkLength(){var inputBox=document.getElementsByClassName("CfnJU HYJSvd")[0];var smsText=document.getElementsByClassName("kf6XZb")[1];var charCount=inputBox.innerText.length;var charsRemaining=CHAR_LIMIT-charCount;if(charsRemaining<0){smsText.innerHTML="MMS<br><span style=\"color:#FF0000;font-size:9px\">"+charsRemaining+"</span>";if(RED_BACKGROUND){inputBox.parentElement.style.background="rgba(255,0,0,0.2)";}}else{smsText.innerHTML="SMS<br><span style=\"color:#00BB00;font-size:9px\">"+charsRemaining+"</span>";if(RED_BACKGROUND){inputBox.parentElement.style.background="";}}}

Changing Settings

Different phones or providers have different character limits before a message is converted to MMS. I found that mine is 765, but yours may be different. Simply edit the value of CHAR_LIMIT in the JavaScript to match your phone. You can also disable the red background that alerts you of a too-long message.