Created
August 2, 2023 07:47
-
-
Save ammgws/9e3e3ce4fa1bd7193bf1367de1b4209c to your computer and use it in GitHub Desktop.
Bookmarklet to get Reddit Video fallback URL (tested in Firefox)
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
javascript:(function() { | |
var currentUrl = window.location.href; | |
if (!currentUrl.includes("reddit")) { | |
alert("This bookmarklet is designed for Reddit pages only."); | |
return; | |
} | |
var jsonUrl = currentUrl + ".json"; | |
fetch(jsonUrl) | |
.then(response => response.json()) | |
.then(data => { | |
var mediaData = data[0]?.data?.children[0]?.data?.media; | |
var fallbackUrl = mediaData?.reddit_video?.fallback_url; | |
if (fallbackUrl) { | |
alert("Fallback URL: " + fallbackUrl); | |
} else { | |
alert("No 'fallback_url' property found in the JSON data."); | |
} | |
}) | |
.catch(error => { | |
alert("Error fetching the JSON data: " + error); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment