Skip to content

Instantly share code, notes, and snippets.

@swthomas55
Forked from Christian-G/slack_scrape.js
Last active August 23, 2022 20:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swthomas55/6028667e845f85f463cd452ce4dfd6e9 to your computer and use it in GitHub Desktop.
Save swthomas55/6028667e845f85f463cd452ce4dfd6e9 to your computer and use it in GitHub Desktop.
Scrape thumbnails from slack
// Works with the "Workspace Directory"
// 1. Visit https://yourteam.slack.com/team
// 2. Paste this code in your console
// 2a. If there are more members than fit on the screen, you must scroll the directory one screen at a time
// and paste the middle block for each screen-full.
// Then run the last line again to fill 'data'.
// 3. In console: JSON.stringify(data) and copy value. It will contain a map from the Slack username to image URL and
// a relative link to the pop-up with user details. I'm still working on retrieving those details.
// 4. Use this 'jq' script to clean it up (I will work on folding this back into the javascript).
// jq 'with_entries(select(.value.image)|{key,"value":({"image":(.value.image//""|gsub("url\\(";"")|gsub("[)\"]";"";"g")),"link":.value.link})})'
// {
// "user1": {
// "image": "https://ca.slack-edge.com/T03G0NWG1-XXXXXXXXX-b0d7eeca45a7-192",
// "link": "/team/XXXXXXXXX"
// },...
var store = {}
$('div.member_details').each(function(i, e) {
var el = $(this);
var userimage = el.find('span.member_preview_link').css('background-image');
// .replace('url(','').replace(')','').replace(/\"/gi, "");
var email = el.find('span.c-unified_member__secondary-name')[0];
var link=el.find('a.c-unified_member').attr('href');
if (email !== undefined) {
store[email.innerHTML] = {image:userimage, link:link};
}
});
var data = $.each(store, function(k, value) { if (value) { console.log(k + " =>", value); } } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment