Skip to content

Instantly share code, notes, and snippets.

@deeja
Last active May 3, 2019 14:58
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 deeja/ab0df063c472b00b549fd2b77a2f9980 to your computer and use it in GitHub Desktop.
Save deeja/ab0df063c472b00b549fd2b77a2f9980 to your computer and use it in GitHub Desktop.
When you want an output of the members' names and photos of your slack team
//// SLACK group listing of people and photos!
/* Get the names and photos of the people in your slack group and prints to A4!
Instructions:
- Go to the web version of your slack channel
- Open the "Channel Details" tab
- Expand "members"
- Click the "See all people"
- Copy and paste this script into your JS console
- Scroll the members list up and down until all the members have been added to the array. You can see the count in the console
- Type show() to Show or print() to Print
*/
var people = [];
var $dialog = $("#channel_membership_dialog_scroller");
$dialog.scroll(function (){
var rows = $(".channel_page_member_row", $dialog);
$.each(rows, function(i, val) {
var currentRow = val
var userName = $(".c-unified_member__display-name",currentRow).text()
// add to array if not existing
var index = people.findIndex(x => x.name == userName)
if (index === -1) {
var userImage = $(".member_preview_link",currentRow).css("background-image") || ""
if (userImage.length != 0) {
userImage = userImage.substring(5)
userImage = userImage.substring(0,userImage.length-4) + "100" // or a size of your choosing
} else {
userImage = "https://placekitten.com/200/200"
}
people.push({name:userName, image: userImage});
}else {
console.log("userName: "+userName+" already exists - Count: "+ people.length)
}
})
});
function show(doPrint){
people.sort((a, b) => (a.name > b.name) ? 1 : -1)
var content = "<html><body><style>figure {float: left; display: block} img {width: 150px} @media print {body{width: 21cm;height: 29.7cm;margin: 30mm 45mm 30mm 45mm; }}</style>";
$.each(people, function(i, person){ content += "<figure><img src='"+person.image +"'/><figcaption>" + person.name +"</figcaption></figure>"});
content += "</body></html>"
var profileWindow = window.open("", "newWindow", "width=1000,height=700")
profileWindow.document.body.innerHTML = content;
if (doPrint) {
profileWindow.print()
}
}
function print(){
show(true);
}
@deeja
Copy link
Author

deeja commented May 3, 2019

Added some styling, sorting and image filling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment