Skip to content

Commit c4a6e55

Browse files
committed
Slack: Make current direct message title accessible as a heading.
1 parent efacf9a commit c4a6e55

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

SlackA11yFixes.user.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
// @include https://*.slack.com/*
1111
// ==/UserScript==
1212

13-
function initial() {
13+
function makeHeading(elem, level) {
14+
elem.setAttribute("role", "heading");
15+
elem.setAttribute("aria-level", level);
16+
}
17+
18+
function initial() {
1419
var elem;
1520
// In DOM order, the footer is earlier than the messages.
1621
// Put it below for a11y (as it appears visually).
@@ -86,15 +91,13 @@ function onNodeAdded(target) {
8691
elem.setAttribute("aria-label", "star");
8792
setStarred(elem);
8893
}
89-
// Make the current channel title a level 2 heading.
90-
if (elem = target.querySelector("#channel_title")) {
91-
elem.setAttribute("role", "heading");
92-
elem.setAttribute("aria-level", "2");
94+
// Make the current channel/direct message title a level 2 heading.
95+
for (elem of target.querySelectorAll("#channel_title, #im_title")) {
96+
makeHeading(elem, 2);
9397
}
9498
// Make level3 headings for day separators in message history, individual search results, individual threads in All Threads.
9599
for (elem of target.querySelectorAll(".day_divider, .search_result_header, .thread_header")) {
96-
elem.setAttribute("role", "heading");
97-
elem.setAttribute("aria-level", "3");
100+
makeHeading(elem, 3);
98101
}
99102
// Kill some extraneous white space.
100103
for (elem of target.querySelectorAll(".message_gutter, .message_content > i.copy_only br")) {

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ It does the following:
7676
- Makes options for each message (Start a thread, Share message, etc.) accessible.
7777
To access these, move the mouse to the text of a message.
7878
They then appear above the author's name as buttons.
79-
- Makes the current channel title, day separators in the message history, the headers of individual search results and the headers of individual threads in All Threads accessible as headings.
79+
- Makes the current channel/direct message title, day separators in the message history, the headers of individual search results and the headers of individual threads in All Threads accessible as headings.
8080
- Reports incoming messages automatically (using a live region).
8181
- Hides an editable area which isn't shown visually.
8282
- Reports suggestions in various autocompletes such as the Quick Switcher and direct messages menu.

0 commit comments

Comments
 (0)