-
-
Save zudsniper/e45c6af75c01e054037f69c36eb4ef29 to your computer and use it in GitHub Desktop.
π΄ fork of userscript to get the damn normal gif URL from giphy...
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
// ==UserScript== | |
// @name GBN2 | |
// @namespace https://website.url | |
// @version 1.7.1 | |
// @description Download GIFs directly from Giphy with a stylish button. | |
// @author me and a mouse | |
// @match *://*/* | |
// @grant GM_xmlhttpRequest | |
// @grant GM_download | |
// @run-at document-end | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Attempt to find and extract the direct GIF URL from the page scripts | |
function extractGifUrl() { | |
const scripts = Array.from(document.scripts); | |
const jsonScript = scripts.find(script => script.type === 'application/ld+json'); | |
if (jsonScript) { | |
try { | |
const json = JSON.parse(jsonScript.textContent); | |
if (json && json.video && json.video.contentUrl) { | |
return json.video.contentUrl.replace(/\.mp4$/, '.gif'); | |
} | |
} catch (error) { | |
console.error('Error parsing Giphy JSON data:', error); | |
} | |
} | |
return null; | |
} | |
// Create and append the vertical download button to the page | |
function createDownloadButton() { | |
const btn = document.createElement('button'); | |
btn.textContent = 'Get Gif'; | |
btn.style.position = 'fixed'; | |
btn.style.top = '50%'; | |
btn.style.right = '0'; | |
btn.style.transform = 'translate(0, -50%) rotate(90deg)'; | |
btn.style.backgroundColor = 'purple'; | |
btn.style.color = 'white'; | |
btn.style.border = 'none'; | |
btn.style.borderRadius = '5px'; | |
btn.style.padding = '10px'; | |
btn.style.cursor = 'pointer'; | |
btn.style.fontSize = '14px'; | |
btn.style.zIndex = '10000'; | |
btn.style.transition = 'background-color 3s ease-in-out'; | |
btn.style.boxShadow = '0 2px 5px rgba(0,0,0,0.3)'; | |
btn.style.whiteSpace = 'nowrap'; | |
// Set up the color transition | |
btn.animate([ | |
{ backgroundColor: 'purple' }, | |
{ backgroundColor: 'pink' } | |
], { | |
duration: 3000, | |
iterations: Infinity, | |
direction: 'alternate' | |
}); | |
btn.addEventListener('click', downloadGif); | |
document.body.appendChild(btn); | |
} | |
// Use GM_xmlhttpRequest and GM_download to handle the download | |
function downloadGif() { | |
const url = extractGifUrl(); | |
if (url) { | |
GM_download(url, 'downloaded_giphy.gif'); | |
} else { | |
alert('GIF URL not found. Make sure you are on a Giphy media page.'); | |
} | |
} | |
// Initialize the script by creating the download button | |
if (document.readyState === 'complete') { | |
createDownloadButton(); | |
} else { | |
window.addEventListener('load', createDownloadButton); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment