status quo

Reduce Twitter's character limit because change is frightening and bigger numbers are intimidating.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         status quo
// @namespace    https://seans.site/
// @version      1.0
// @description  Reduce Twitter's character limit because change is frightening and bigger numbers are intimidating.
// @author       Sean S. LeBlanc
// @match        https://twitter.com/
// @grant        none
// @require http://code.jquery.com/jquery-1.12.4.min.js
// ==/UserScript==

(function() {
    'use strict';
    var maxCharacters = 70;

    var tweetCharCount = document.querySelector('#timeline > div.timeline-tweet-box > div > form > div.TweetBoxToolbar > div.TweetBoxToolbar-tweetButton.tweet-button > span');
    var countStyle = window.getComputedStyle(tweetCharCount);
    var newCount = document.createElement("p");
    newCount.innerText = maxCharacters;
    newCount.style.cssText = countStyle.cssText;
    tweetCharCount.style.visibility = "hidden";
    tweetCharCount.insertAdjacentElement('afterend', newCount);
    var tweetLength = 0;
    var charactersLeft = maxCharacters;
    $(document).on("input", '#tweet-box-home-timeline', function(event){
        var tweetBox = event.currentTarget.childNodes[0];
        if(tweetBox.innerText.length > maxCharacters){
            var t=document.createTextNode(tweetBox.innerText.substr(0,maxCharacters));
            tweetBox.innerText = "";
            //selection code adapted from: https://stackoverflow.com/questions/17497661/insert-text-before-and-after-selection-in-a-contenteditable
            var sel = window.getSelection();
            if (sel.rangeCount > 0) {
                var range = sel.getRangeAt(0);
                var startNode = range.startContainer;
                var startOffset = range.startOffset;
                var boundaryRange = range.cloneRange();
                boundaryRange.collapse(false);
                boundaryRange.setStart(startNode, startOffset);
                boundaryRange.collapse(true);
                boundaryRange.insertNode(t);
                range.setStartAfter(t);
                range.setEndAfter(t);
                sel.removeAllRanges();
                sel.addRange(range);
            }
        }
        tweetLength = tweetBox.innerText.length;
        charactersLeft = maxCharacters - tweetLength;
        newCount.innerText = charactersLeft.toString(10);
    });
})();