Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
In SO chat, adds a label indicating the character count of your message
// ==UserScript==
// @name char count adder (SO Chat)
// @namespace .
// @description Adds a label indicating the character count of your message
// @include http://chat.stackoverflow.com/rooms/*
// @include https://chat.stackoverflow.com/rooms/*
// @version 3
// @grant none
// ==/UserScript==
var max_one_liner = 150;
var max = 500;
var row = document.getElementById("chat-buttons");
var box = document.createElement("span");
row.appendChild(box);
function update_box(){
var size = document.getElementById("input").value.length;
var message = " " + size + " char" + (size==1 ? "" : "s");
if (size == 0){
message = "";
}
else if (size > max){
message += " (Too large to submit by " + (size - max) + ")";
}
else if (size > max_one_liner){
message += " (Too large to fit starred list by " + (size - max_one_liner) + ")";
}
box.innerHTML = message;
}
window.setInterval(update_box, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment