Skip to content

Commit 6b95fa2

Browse files
Add script for the Telegram web interface (#9)
1 parent 8e5dcf5 commit 6b95fa2

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

TelegramA11yFixes.user.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// ==UserScript==
2+
// @name Telegram Accessibility Fixes
3+
// @namespace http://axSGrease.nvaccess.org/
4+
// @description Improves the accessibility of Telegram.
5+
// @author Michael Curran <mick@nvaccess.org>
6+
// @copyright 2016 NV Access Limited
7+
// @license GNU General Public License version 2.0
8+
// @version 2016.1
9+
// @grant GM_log
10+
// @include https://web.telegram.org/*
11+
// ==/UserScript==
12+
13+
function init() {
14+
var elem;
15+
16+
if (elem = document.querySelector(".im_history_messages_peer")) {
17+
// Chat history.
18+
elem.setAttribute("aria-live", "polite");
19+
}
20+
}
21+
22+
function onNodeAdded(target) {
23+
if(target.classList.contains('im_content_message_wrap')) {
24+
target.setAttribute("aria-live", "polite");
25+
}
26+
}
27+
28+
function onClassModified(target) {
29+
}
30+
31+
var observer = new MutationObserver(function(mutations) {
32+
for (var mutation of mutations) {
33+
try {
34+
if (mutation.type === "childList") {
35+
for (var node of mutation.addedNodes) {
36+
if (node.nodeType != Node.ELEMENT_NODE)
37+
continue;
38+
onNodeAdded(node);
39+
}
40+
} else if (mutation.type === "attributes") {
41+
if (mutation.attributeName == "class")
42+
onClassModified(mutation.target);
43+
}
44+
} catch (e) {
45+
// Catch exceptions for individual mutations so other mutations are still handled.
46+
GM_log("Exception while handling mutation: " + e);
47+
}
48+
}
49+
});
50+
observer.observe(document, {childList: true, attributes: true,
51+
subtree: true, attributeFilter: ["class"]});
52+
53+
init();

readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,12 @@ It does the following:
7171
- Makes day separators in the message history and the about channel pane heading accessible as headings.
7272
- Reports incoming messages automatically (using a live region).
7373
- Hides an editable area which isn't shown visually.
74+
75+
### Telegram accessibility fixes
76+
[Download Telegram Accessibility Fixes](https://github.com/nvaccess/axSGrease/raw/master/TelegramA11yFixes.user.js)
77+
78+
This script improves the accessibility of the [Telegram instant messaging](https://web.telegram.org/) web interface.
79+
80+
It so far does the following:
81+
82+
- Marks the chat history as a live region so new messages are announced automatically.

0 commit comments

Comments
 (0)