Last active
March 25, 2022 00:59
-
-
Save felixrieseberg/fdccbd2d1ab91be42c796564576e5fce to your computer and use it in GitHub Desktop.
Slack: Get a list of your channels (excluding DMs, group chats, and archived/private channels)
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
// Open up the Slack Developer Tools by entering "/slackdevtools" | |
// in the message input. | |
// First, run this. The client will reload. | |
slackDebug.enable() | |
// Then, get channels. See "filterChannels" to remove channels | |
// beginning with a certain prefix. | |
(function getMyChannels() { | |
const allChannels = slackDebug.storeInstance.getStateByTeamId(slackDebug.activeTeamId).channels.__proto__ | |
let myChannels = [] | |
// Filter out channels beginnging with... | |
let filterChannels = ['ir-', 'bc-', 'ex-'] | |
for (const key of Object.keys(allChannels)) { | |
const channel = allChannels[key] | |
// No DMs, MPDMs, etc | |
if (!channel.is_channel || !channel.is_member) continue | |
// No channels nobody can join | |
if (channel.is_archived || channel.is_private) continue | |
// No garbage | |
if (channel.isNonExistent || channel.isUnknown || channel.fromAnotherTeam) continue | |
// Filter prefixes | |
if (filterChannels.find((prefix) => channel.name.startsWith(prefix))) { | |
continue | |
} | |
myChannels.push({ | |
name: channel.name, | |
topic: channel.topic?.value, | |
purpose: channel.purpose?.value, | |
}) | |
} | |
myChannels.sort((a, b) => a.name.localeCompare(b.name)) | |
// Make a new window | |
const channelWindow = window.open('about:blank') | |
const list = channelWindow.document.createElement('ul') | |
channelWindow.document.body.style.fontFamily = `-apple-system, BlinkMacSystemFont` | |
channelWindow.document.body.appendChild(list) | |
for (const channel of myChannels) { | |
const li = channelWindow.document.createElement('li') | |
const small = channelWindow.document.createElement('small') | |
const name = `#${channel.name}` | |
const purpose = channel.purpose ? ` (${channel.purpose})` : `` | |
small.appendChild(channelWindow.document.createTextNode(purpose)) | |
li.appendChild(channelWindow.document.createTextNode(name)) | |
li.appendChild(small) | |
list.appendChild(li) | |
} | |
})() | |
// Then, disable SlackDebug. The client will reload. | |
slackDebug.disable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment