Skip to content

Instantly share code, notes, and snippets.

@richarddewit
Created July 14, 2023 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richarddewit/0ac502ac9e3759288b343fdbb0e5682e to your computer and use it in GitHub Desktop.
Save richarddewit/0ac502ac9e3759288b343fdbb0e5682e to your computer and use it in GitHub Desktop.
Download Telegram Stickers (UPDATED)
// DOM query helpers
// These two do 90% of what you need JQuery for
function qs(query, el = window.document) {
return el.querySelector(query);
}
function qsa(query, el = window.document) {
return Array.from(el.querySelectorAll(query));
}
// Trigger a download
function download(image) {
// Create a dummy element
var a = document.createElement('a');
a.href = image;
// `download` attribute means that clicks trigger download
a.download = "";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
function downloadStickers() {
// Find all sticker sets
const sets = qsa('#content-stickers .emoji-category')
// We need it's title to prompt users
.map(set => {
const $title = qs('.category-title', set);
const $items = qs('.category-items', set);
return {
title: $title.innerText,
node: $items,
};
})
// Those without key aren't packs. "Frequently used" for example.
.filter(({title, set}) => title !== '' && title !== "Recent");
// Join them into a list of keys-titles
const availableSets = sets
.map(({title}, i) => `[${i}]: ${title}`)
.join('\n')
console.log(availableSets)
// Ask which pack the user want to download
const selectedSet = prompt(availableSets);
// Find all images
qsa('img', sets[+selectedSet].node)
// Only care about it's URL
.map(i => i.attributes.src.value)
// Filter those with `sticker` in the URL
// .filter(i => /sticker/.test(i)))
// Download all
.forEach(download);
}
downloadStickers()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment