-
-
Save miketoth/76bf6b657def519b4135 to your computer and use it in GitHub Desktop.
Giphy on hipchat (no integration needed)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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(); | |
}; | |
})(); |
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
uses command
/giphy
like the good old days :)