Skip to content

Instantly share code, notes, and snippets.

@bahamas10
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save bahamas10/10095066 to your computer and use it in GitHub Desktop.

Select an option

Save bahamas10/10095066 to your computer and use it in GitHub Desktop.
slack preformat pastes automatically

drop this into the javascript console on a slack chat to have pastes automatically show up as preformatted text.

var TS_view_submit = TS.view.submit.bind(TS.view); TS.view.submit = function() { var msgInput = document.getElementById('message-input'); if (msgInput.value.indexOf('\n') > -1) msgInput.value = '```\n' + msgInput.value + '\n```'; return TS_view_submit.apply(this, arguments); }

a more readable version

// store the original function
var TS_view_submit = TS.view.submit.bind(TS.view);

// hijack it
TS.view.submit = function() {
    // get the input textarea
    var msgInput = document.getElementById('message-input');
    
    // if the input has a newline, make it preformatted
    if (msgInput.value.indexOf('\n') > -1)
        msgInput.value = '```\n' + msgInput.value + '\n```';
   
    // call the original
    return TS_view_submit.apply(this, arguments);
}
@bahamas10
Copy link
Copy Markdown
Author

javascript:(function() {if (window.DAVE_PATCHED_PREFORMAT) return; window.DAVE_PATCHED_PREFORMAT = Date.now(); var TS_view_submit = TS.view.submit.bind(TS.view); TS.view.submit = function() { var msgInput = document.getElementById('message-input'); if (msgInput.value.indexOf('\n') > -1) msgInput.value = '```\n' + msgInput.value + '\n```'; return TS_view_submit.apply(this, arguments); };  alert('patched'); })();

bookmarklet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment