Skip to content

Instantly share code, notes, and snippets.

@alexamy
Last active March 30, 2024 22:29
Show Gist options
  • Save alexamy/67dac86a9e604f29318982a41f7ab53d to your computer and use it in GitHub Desktop.
Save alexamy/67dac86a9e604f29318982a41f7ab53d to your computer and use it in GitHub Desktop.
Extract emojis list as JSON & CSV from https://*.slack.com/customize/emoji
// extract all emojis from https://*.slack.com/customize/emoji
// open devtools console and paste this code
// tested in google chrome
await getEmojis();
async function getEmojis() {
const result = {};
const allCount = parseInt(document.querySelector('.p-customize_emoji_wrapper__count').textContent);
const log = (s) => console.log('[sep] %c%s', 'background: #2f3640; color: #00a8ff; font-weight: bold; font-size: 14px; padding: 1px', s);
let lastVisited = '';
while(true) {
const list = document.querySelector('.c-virtual_list__scroll_container');
const emojis = Array.from(list.children);
const data = emojis.map(getEmojiData);
data.forEach(emoji => {
result[emoji.name] = emoji;
});
log(`Emojis saved: ${Object.keys(result).length}/${allCount}...`);
const last = emojis.slice(-5)[0];
if(lastVisited === last.textContent) break;
lastVisited = last.textContent;
last.scrollIntoView();
await new Promise(resolve => setTimeout(resolve, 3500));
}
log('Finished. Downloading emojis JSON.');
download(Object.values(result));
}
function download(emojis) {
const json = JSON.stringify(emojis, null, 2);
downloadFile(json, 'emojis.json');
const headers = Object.keys(emojis[0]);
const values = emojis.map(emoji => {
return headers.map(key => `"${emoji[key]}"`);
});
const csv = [headers].concat(values).map(row => row.join(',')).join('\n');
downloadFile(csv, 'emojis.csv');
}
function downloadFile(data, fileName) {
const file = new Blob([data], { type: 'text/json' });
const a = document.createElement('a');
a.href = URL.createObjectURL(file);
a.download = fileName;
document.body.appendChild(a);
a.click();
}
// div.c-virtual_list__item
function getEmojiData(emoji) {
const table = emoji.querySelector('.c-table_view_row.p-customize_emoji_list__row');
const [image, name, date, author] = Array.from(table.children);
return {
src: image.querySelector('img').src,
name: name.querySelector('.black').textContent.trim(),
origDate: date.textContent.trim(),
date: convertDate(date.textContent.trim()),
author: author.textContent.trim(),
}
}
// slack date to YY-MM-DD
// has a quirk that date with december before current year has no year number
function convertDate(dateStr) {
const months = {
January: '01', February: '02', March: '03', April: '04',
May: '05', June: '06', July: '07', August: '08',
September: '09', October: '10', November: '11', December: '12',
};
const currentYear = (new Date()).getFullYear();
const currentMonth = `0${(new Date()).getMonth() + 1}`.slice(-2);
const [date, yearS] = dateStr.split(',');
const [monthS, dayOrd] = date.split(' ');
const dayS = dayOrd.slice(0, -2);
const day = `0${dayS}`.slice(-2);
const month = months[monthS];
const year = yearS ? Number(yearS.trim()) : (month <= currentMonth ? currentYear : currentYear - 1);
return `${year}-${month}-${day}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment