/giphy.download.gif.js Secret
Created
May 6, 2021 23:09
Star
You must be signed in to star a gist
Download a Giphy in javascript from it's file URL
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
(async () => { | |
//create new a element | |
let a = document.createElement('a'); | |
// get image as blob | |
let response = await fetch('https://media2.giphy.com/media/DvyLQztQwmyAM/giphy.gif?cid=e9ff928175irq2ybzjyiuicjuxk21vv4jyyn0ut5o0d7co50&rid=giphy.gif'); | |
let file = await response.blob(); | |
// use download attribute https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Attributes | |
a.download = 'myGif'; | |
a.href = window.URL.createObjectURL(file); | |
//store download url in javascript https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes#JavaScript_access | |
a.dataset.downloadurl = ['application/octet-stream', a.download, a.href].join(':'); | |
//click on element to start download | |
a.click(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment