Skip to content

Instantly share code, notes, and snippets.

@Kurty00
Last active April 16, 2023 19:41
Show Gist options
  • Save Kurty00/f4c5f293075cac840e56b81347078840 to your computer and use it in GitHub Desktop.
Save Kurty00/f4c5f293075cac840e56b81347078840 to your computer and use it in GitHub Desktop.
Downloads Mastodon Emoji
getEmoji("fedi.fun");
function loadJSON(url, callback) {
var xhr = new XMLHttpRequest();
xhr.overrideMimeType("application/json");
xhr.open("GET", url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
callback(xhr.responseText);
}
};
xhr.send(null);
}
function downloadFile(url, filename) {
fetch(url)
.then((response) => response.blob())
.then((blob) => {
const url = window.URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
});
}
function getEmoji(instance) {
loadJSON(`https://${instance}/api/v1/custom_emojis`, function (response) {
data = JSON.parse(response);
for (var l of data) {
console.log(l.shortcode + "." + l.url.split(".")[3], l.url);
downloadFile(l.url, l.shortcode + "." + l.url.split(".")[3]);
}
console.log(`Found ${data.length} Emoji on ${instance}.`)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment