170文字
1分
編集

Slackのsubteam IDとchannel IDをまとめて取得する

Slackをブラウザで開き、次のスクリプトを検証ツールのConsoleで実行すれば、現在表示されているグループメンションのsubteam IDをまとめて取得できる。

js
copy(Array.from(new Map($$("[data-user-group-id]").map(e => ([e.innerText,  e.dataset.userGroupId ])))).map(([label,id]) => ({label, id})))

実行するとクリップボードに次のような形式でコピーされる。

json
[
  {
    "label": "@user_group_name_1",
    "id": "SUBTEAM_ID_1"
  },
  {
    "label": "@user_group_name_2",
    "id": "SUBTEAM_ID_2"
  },
  // ...
]

このスクリプトは、Slack内のグループメンションのHTML要素が次のようになっていることを利用している。

html
<a data-user-group-id="SUBTEAM_ID" >@user_group_name</a>

Channel IDの場合は、サイドバーを表示した状態で次のスクリプトを実行すれば、すべてのチャンネルのIDをまとめて取得できる。

js
copy(Array.from(new Map($$("[data-qa-channel-sidebar-channel-id]").map(e => ([e.innerText,  e.dataset.qaChannelSidebarChannelId ])))).map(([label,id]) => ({label, id})))
編集