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