Last active
May 26, 2019 06:58
-
-
Save fanatid/b9701e584c0e00ec3d40bb1d400db1f7 to your computer and use it in GitHub Desktop.
Download custom emojis from slack
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
const fs = require('fs') | |
const fetch = require('node-fetch') | |
;(async () => { | |
const data = JSON.parse(fs.readFileSync('./data.json', 'utf-8')) | |
// const html = fs.readFileSync('./x.html', 'utf-8') | |
// const customTag = '<h3 class="p-emoji_picker__heading">Custom</h3>' | |
// const text = html.includes(customTag) ? html.slice(html.indexOf(customTag)) : html | |
// const re = /<span class="emoji emoji-sizer" style="background-image:url\((.*?)\)" data-codepoints="(.*?)">/g | |
// for (;;) { | |
// const match = re.exec(text) | |
// if (!match) break | |
// data[match[2]] = match[1] | |
// } | |
// fs.writeFileSync('./data.json', JSON.stringify(data, null, 2), 'utf-8') | |
try { | |
fs.mkdirSync('./emojis') | |
} catch (err) { | |
if (err.code !== 'EEXIST') throw err | |
} | |
for (const [key, value] of Object.entries(data)) { | |
console.log(key, value) | |
const resp = await fetch(value) | |
const body = await resp.arrayBuffer() | |
const ext = value.match(/\.(\w+)$/)[1] | |
fs.writeFileSync(`./emojis/${key}.${ext}`, Buffer.from(body)) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment