Skip to content

Instantly share code, notes, and snippets.

@mxmtsk
Last active December 15, 2017 19:53
Show Gist options
  • Save mxmtsk/388c1674f5880ce110c97f5c06c403cc to your computer and use it in GitHub Desktop.
Save mxmtsk/388c1674f5880ce110c97f5c06c403cc to your computer and use it in GitHub Desktop.
Simple Tampermonkey Script that will show the tweet character count on Twitter!
// ==UserScript==
// @name Show Twitter Count
// @namespace mxmtsk.twittercount
// @version 0.1
// @description Show good old twitter count instead of the donut
// @author mxmtsk
// @match https://twitter.com/*
// @grant none
// @run-at document-idle
// ==/UserScript==
function getForms() {
// add event listener to forms not already intialized
jQuery('form.tweet-form[data-has-count-listener!="1"]').on('uiUpdateCounter', function(e, data) {
// only show until 280 characters so twitters own warnings will display if you exceed the limit
if(data.tweetLength <= 280) {
var length = parseInt(data.tweetLength);
// if you'd much rather like to count down to zero instead of up comment the line in
// length = 280 - data.tweetLength
jQuery(this).find('.tweet-counter').text(length);
}
});
jQuery('form.tweet-form[data-has-count-listener!="1"]').attr('data-has-count-listener', "1");
}
document.onreadystatechange = function() {
getForms();
// This will look up new forms on the page every second
setInterval(getForms, 1000);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment