Created
May 23, 2020 04:18
-
-
Save duke79/1fd382fc182a04978651d5351e86f402 to your computer and use it in GitHub Desktop.
giphy download gif
This file contains hidden or 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
| var gifAlt = document.getElementsByTagName("h1")[0].textContent; | |
| var myImage = getImagesByAlt(gifAlt)[0]; | |
| var downloadWithLink = (link) => { | |
| var a; | |
| a = document.createElement('a'); | |
| // myIframe.src = 'https://media.giphy.com/media/h2MLtoOjxtkGY/giphy.gif'; | |
| a.href = link; | |
| // iframe.id = 'directGif'; | |
| a.style.display = 'none'; | |
| document.body.appendChild(a); | |
| a.click(); | |
| }; | |
| var req = new XMLHttpRequest(); | |
| var res; | |
| req.open('GET', myImage.currentSrc); | |
| req.onload = () => { | |
| res = req.responseText; | |
| // if(req.status == 200) | |
| // console.log(req.responseText); | |
| // URL.createObjectURL(req.responseText); | |
| // console.log({ URL }); | |
| var uri = 'data:image/gif;base64,' + btoa(unescape(encodeURIComponent(res))); | |
| downloadWithLink(uri); | |
| }; | |
| req.send(null); | |
| // var myIframe; | |
| // myIframe = document.createElement('iframe'); | |
| // // myIframe.src = 'https://media.giphy.com/media/h2MLtoOjxtkGY/giphy.gif'; | |
| // myIframe.src = myImage.currentSrc | |
| // // iframe.id = 'directGif'; | |
| // myIframe.style.display = 'none'; | |
| // document.body.appendChild(myIframe); | |
| // var elmnt | |
| // myIframe.addEventListener("load", function() { | |
| // elmnt = myIframe.contentWindow.document.getElementsByTagName("img"); | |
| // console.log(elmnt[0].currentSrc); | |
| // }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment