diff --git a/js/plugins.js b/js/plugins.js index 8a84758..15657d2 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -353,6 +353,25 @@ plugins.factory('userPlugins', function() { } }); + /* match giphy links and display the assocaited gif images + * sample input: http://giphy.com/gifs/eyes-shocked-bird-feqkVgjJpYtjy + * sample output: https://media.giphy.com/media/feqkVgjJpYtjy/giphy.gif + */ + var giphyPlugin = new UrlPlugin('Giphy', function(url) { + var regex = /^https?:\/\/giphy.com\/gifs\/.*-.*\/?/i; + if (url.match(regex)) { + /* if the url does not contain a trailing slash, add it */ + if (! url.match(/\/$/i)) { url = url + "/"; } + /* upgrade any http links to tls, yeah crypto */ + if (url.match(/^http:/i)) { url.replace(/http:/, "https:"); } + /* change the url to refrence the giphy cdn url, not the userfacing webserver */ + url = url.replace(/\/giphy.com\//i,"/media.giphy.com/"); + url = url.replace(/\/gifs\/.*-/i,"/media/"); + url = url + "giphy.gif"; + return ''; + } + }); + var tweetPlugin = new UrlPlugin('Tweet', function(url) { var regexp = /^https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(?:es)?\/(\d+)/i; var match = url.match(regexp); @@ -391,7 +410,7 @@ plugins.factory('userPlugins', function() { }); return { - plugins: [youtubePlugin, dailymotionPlugin, allocinePlugin, imagePlugin, videoPlugin, spotifyPlugin, cloudmusicPlugin, googlemapPlugin, asciinemaPlugin, yrPlugin, gistPlugin, tweetPlugin, vinePlugin] + plugins: [youtubePlugin, dailymotionPlugin, allocinePlugin, imagePlugin, videoPlugin, spotifyPlugin, cloudmusicPlugin, googlemapPlugin, asciinemaPlugin, yrPlugin, gistPlugin, giphyPlugin, tweetPlugin, vinePlugin] }; diff --git a/test/unit/plugins.js b/test/unit/plugins.js index e179c0a..34be685 100644 --- a/test/unit/plugins.js +++ b/test/unit/plugins.js @@ -139,6 +139,15 @@ describe('filter', function() { plugins); })); + it('should recognize giphy gifs', inject(function(plugins) { + expectTheseMessagesToContain([ + 'https://giphy.com/gifs/eyes-shocked-bird-feqkVgjJpYtjy/', + 'http://giphy.com/gifs/funny-cat-FiGiRei2ICzzG', + ], + 'Giphy', + plugins); + })); + it('should recognize tweets', inject(function(plugins) { expectTheseMessagesToContain([ 'https://twitter.com/DFB_Team_EN/statuses/488436782959448065',