Skip to content

Instantly share code, notes, and snippets.

@miketoth
Forked from snit-ram/hipchat-giphy
Last active December 7, 2017 20:50
Show Gist options
  • Save miketoth/76bf6b657def519b4135 to your computer and use it in GitHub Desktop.
Save miketoth/76bf6b657def519b4135 to your computer and use it in GitHub Desktop.
Giphy on hipchat (no integration needed)
(function () {
function giphy(word, callback) {
var xhr = new XMLHttpRequest();
var url = 'https://api.giphy.com/v1/gifs/translate?rating=pg-13&api_key=dc6zaTOxFJmzC&s=' + encodeURIComponent(word);
xhr.open('GET', url);
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 command = '/giphy';
var temp = chat.send_message.bind(chat);
chat.send_message = function() {
console.log('something');
var messageBox = document.querySelector('#message_input');
var index = messageBox.value.indexOf(command);
if(index > -1) {
var text = messageBox.value.split(command);
console.log(text);
giphy(text[1], function(url) {
messageBox.value = url;
temp();
});
}
temp();
};
})();
@TheDesignerXD
Copy link

Which of the many packaged files should we add this to? chat.html?

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