twitter - How to tweet highlighted text? - Stack Overflow

PHOTO EMBED

Fri Mar 05 2021 04:53:54 GMT+0000 (Coordinated Universal Time)

Saved by @richard

function getSelectionText() {
var text = "";
if (window.getSelection) {
    text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
    text = document.selection.createRange().text;
}
return text;
}
$(document).ready(function () {
$('div,p').mouseup(function (e) {
    if (getSelectionText() != "") {
        window.open('https://twitter.com/intent/tweet?text='+encodeURI(getSelectionText()) + '&url=' + encodeURI(document.URL));
    }
})
});
content_copyCOPY

https://stackoverflow.com/questions/19188896/how-to-tweet-highlighted-text/20947986