Skip to content

Instantly share code, notes, and snippets.

@Pagliacii
Forked from lubien/stickers-downloader.js
Created April 27, 2018 03:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Pagliacii/6f05589ca587328afd4142381330903e to your computer and use it in GitHub Desktop.
Download all visible telegram stickers images
// How to download telegram sticker images
/*
1. Go to Telegram Web;
2. Open console (F12);
3. Paste the code below in the console and press Enter;
4. Open your stickers menu and make sure you see the sticker pack you want to download (so Telegram will load it).
5. At the console paste and run "downloadStickers()" any time you want to download a pack.
6. [Convert .webm to another format](http://www.freewaregenius.com/convert-webp-image-format-jpg-png-format/);
7. Happy hacking.
If you close the tab or refresh it, you should do step 3 again.
*/
// Main function
function downloadStickers() {
// Find all sticker sets
const sets = querySelectorAll('.composer_stickerset_wrap')
// We need it's title to prompt users
.map(set => {
const $title = querySelector('.composer_stickerset_title', set);
return {
key: $title.attributes['data-stickerset'].value,
title: $title.innerText,
node: set,
};
})
// Those without key aren't packs. "Frequently used" for example.
.filter(({key}) => key !== '');
// Ask which pack the user want to download
const selectedSet = prompt(
// Join them into a list of keys-titles
sets
.map(({title}, i) => `[${i}]: ${title}`)
.join('\n')
);
// Find all images
querySelectorAll('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);
}
// DOM query helpers
// These two do 90% of what you need JQuery for
const querySelector = (query, el = window.document) =>
el.querySelector(query);
const querySelectorAll = (query, el = window.document) =>
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment