Skip to content

Instantly share code, notes, and snippets.

@swalberg
Created November 10, 2014 19:26
Show Gist options
  • Save swalberg/0f6dc4f58bae6e653082 to your computer and use it in GitHub Desktop.
Save swalberg/0f6dc4f58bae6e653082 to your computer and use it in GitHub Desktop.
Post to HipChat from browser (default to highlighted text)
// Get your token from the HipChat website "API Access" menu
// Add the token and room where indicated in this line (we use "Easylog")
// Make a new page in your button bar with this in it:
javascript:(function(){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;} var auth_token = "MYTOKENGOESHERE";var room = "Easylog";var ajax = new XMLHttpRequest;var url = "https://api.hipchat.com/v2/room/" + encodeURIComponent(room) + "/notification?auth_token=" + auth_token;ajax.open('POST', url, true);ajax.setRequestHeader("Content-type", "application/json");var message = prompt('log entry?', getSelectionText()); if (message) {ajax.send('{"color":"green", "message": "' + message + '"}');} })()
// getSelectionText() copied from http://stackoverflow.com/questions/5379120/get-the-highlighted-selected-text
@swalberg
Copy link
Author

We have a HipChat room that we post changes to so that team mates can see what's going on. The code above implements a bookmarklet that prompts you for a message to send to the room from your browser. The default value for this prompt is the currently highlighted text on the screen, which makes copying issue descriptions or urls fairly easy.

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