Skip to content

Instantly share code, notes, and snippets.

@snit-ram
Last active September 13, 2018 18:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save snit-ram/245a9d4a97b63ec82e72 to your computer and use it in GitHub Desktop.
Save snit-ram/245a9d4a97b63ec82e72 to your computer and use it in GitHub Desktop.
hipchat-giphy "integration"
(function () {
function giphy(word, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.giphy.com/v1/gifs/translate?api_key=dc6zaTOxFJmzC&s=' + encodeURIComponent(word));
xhr.onreadystatechange = function(e) {
if(xhr.readyState === 4) {
var url = JSON.parse(e.target.responseText).data.images.fixed_height.url;
callback(url);
}
};
xhr.send();
}
var giphyForm = document.createElement('form');
giphyForm.innerHTML = '<input id="giphybox" placeholder="giphy">';
giphyForm.style.position = 'absolute';
giphyForm.style.right = '110px';
giphyForm.style.top = '5px';
giphyForm.style.width= '180px';
giphyForm.style.height = '24px';
var topbar = document.querySelector('#top_bar');
var searchButton = document.querySelector('#search_button');
topic.style.marginRigh = '200px';
topbar.insertBefore(giphyForm, searchButton);
giphyForm.addEventListener('submit', function(e){
e.preventDefault();
var giphybox = document.querySelector('#giphybox');
var value = giphybox.value;
giphyForm.reset();
giphy(value, function(url){
document.querySelector('#message_input').value = 'giphy: ' + value;
chat.send_message();
document.querySelector('#message_input').value = url;
chat.send_message();
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment