Skip to content

Commit c11166e

Browse files
Tuukka Ojalajcsteh
authored andcommitted
Slack: Update to work with the recent message list changes.
- Fix new messages not being announced automatically - There's no need to assign the listitem role anymore - Slack has made the star button accessible themselves - Fix headings for day separators
1 parent ad4d8d3 commit c11166e

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

SlackA11yFixes.user.js

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ function makeHeading(elem, level) {
3535
}
3636
}
3737

38-
// Make the starred status accessible.
39-
function setStarred(elem) {
40-
elem.setAttribute("aria-pressed",
41-
elem.classList.contains("starred") ? "true" : "false");
42-
}
43-
4438
function message(text, suppressRepeats) {
4539
var live = document.getElementById("aria_live_announcer");
4640
if (suppressRepeats && live.textContent == text) {
@@ -66,37 +60,28 @@ function onNodeAdded(target) {
6660
return;
6761
}
6862
// Report incoming messages and make them list items.
69-
if (target.matches("#msgs_div .message:last-child, #threads_msgs .message:last-child, #convo_container .message:last-child") && !target.classList.contains("unprocessed")) {
63+
if (target.matches("#messages_container .c-virtual_list__item:last-child, #threads_msgs .message:last-child, #convo_container .message:last-child") && !target.classList.contains("unprocessed")) {
7064
// Just shove text into a live region that's already used for stuff like this.
7165
// It'd better/less hacky if the messages area itself were a live region,
7266
// but doing this results in double/triple speaking for some reason.
7367
// We also don't want the time reported in this case.
74-
sender = target.querySelector(".message_sender").textContent;
75-
body = target.querySelector(".message_body").textContent;
68+
sender = target.querySelector(".c-message__sender").textContent;
69+
body = target.querySelector(".c-message__body").textContent;
7670
message(sender + " " + body);
77-
target.setAttribute("role", "listitem");
7871
}
7972
var elem;
80-
// Make existing messages list items.
81-
for (elem of target.querySelectorAll("#msgs_div .message, #threads_msgs .message, #convo_container .message, #search_results_container .message"))
82-
elem.setAttribute("role", "listitem");
8373
for (elem of target.querySelectorAll(".copy_only")) {
8474
// This includes text such as the brackets around message times.
8575
// These chunks of text are block elements, even though they're on the same line.
8676
// Remove the elements from the tree so the text becomes inline.
8777
elem.setAttribute("role", "presentation");
8878
}
89-
// Channel/message star controls.
90-
for (elem of target.querySelectorAll(".star")) {
91-
elem.setAttribute("aria-label", "star");
92-
setStarred(elem);
93-
}
9479
// Make the current channel/direct message title a level 2 heading.
9580
for (elem of target.querySelectorAll("#channel_title, #im_title")) {
9681
makeHeading(elem, 2);
9782
}
9883
// Make level3 headings for day separators in message history, individual search results, individual threads in All Threads.
99-
for (elem of target.querySelectorAll(".day_divider, .search_result_header, .thread_header")) {
84+
for (elem of target.querySelectorAll(".c-message_list__day_divider__label__pill, .search_result_header, .thread_header")) {
10085
makeHeading(elem, 3);
10186
}
10287
// Kill some extraneous white space.
@@ -109,10 +94,7 @@ function onClassModified(target) {
10994
var classes = target.classList;
11095
if (!classes)
11196
return;
112-
if (classes.contains("star")) {
113-
// Starred state changed.
114-
setStarred(target);
115-
} else if (classes.contains("highlighted")) {
97+
if (classes.contains("highlighted")) {
11698
// Autocomplete selection.
11799
// We use a live region because ARIA autocompletes don't work so well
118100
// for a control which selects the first item as you type.

readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ This script improves the accessibility of [Slack](https://www.slack.com/).
7070
It does the following:
7171

7272
- Reorders some elements which appear in the wrong place for accessibility. For example, using this script, the input area appears near the bottom of the page as it does visually instead of at the top.
73-
- Makes messages accessible as list items.
7473
- Makes message timestamps appear on a single line instead of crossing several lines.
75-
- Makes star controls (and their statuses) accessible.
7674
- Makes options for each message (Start a thread, Share message, etc.) accessible.
7775
To access these, move the mouse to the text of a message.
7876
They then appear above the author's name as buttons.

0 commit comments

Comments
 (0)