-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GiphyGifs.min.js
1 lines (1 loc) · 1.03 KB
/
GiphyGifs.min.js
1
javascript:/* GiphyGifs.js (https://github.com/Bellisario/GiphyGifs.js) minified code (under MIT license) */(function(){if(document.readyState!=='complete'){return alert('Page is not completely loaded: re-run this script after page load.');};function getGif(){try{return document.querySelector('video+img').src;}catch(e){return false;};};async function download(url,name){var a=document.createElement('a');var response=await fetch(url);var file=await response.blob();a.download=name;a.href=window.URL.createObjectURL(file);a.dataset.downloadurl=['application/octet-stream',a.download,a.href].join(':');a.click();};if(!location.href.startsWith('https://giphy.com/gifs/')){return alert('Cannot get gif from this URL. It needs to be as this:\nhttps://giphy.com/gifs/...');};var gifUrl=getGif();if(!gifUrl){return alert('Failed to get gif.');};var name=prompt('Ready to download!\nWhat name you want to use (without extension)?\nIf input is blank will be used the default name.','giphyGif');if(!name||name===' '){name='giphyGif';};download(gifUrl,name);})();