Skip to content

Instantly share code, notes, and snippets.

@kms70847
Last active November 19, 2019 16:37
Show Gist options
  • Save kms70847/423dc31f346d9a932244 to your computer and use it in GitHub Desktop.
Save kms70847/423dc31f346d9a932244 to your computer and use it in GitHub Desktop.
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