diff --git a/TelegramA11yFixes.user.js b/TelegramA11yFixes.user.js new file mode 100644 index 0000000..330e191 --- /dev/null +++ b/TelegramA11yFixes.user.js @@ -0,0 +1,53 @@ +// ==UserScript== +// @name Telegram Accessibility Fixes +// @namespace http://axSGrease.nvaccess.org/ +// @description Improves the accessibility of Telegram. +// @author Michael Curran +// @copyright 2016 NV Access Limited +// @license GNU General Public License version 2.0 +// @version 2016.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(); diff --git a/readme.md b/readme.md index f89e12b..2d08251 100644 --- a/readme.md +++ b/readme.md @@ -71,3 +71,12 @@ It does the following: - Makes day separators in the message history and the about channel pane heading accessible as headings. - Reports incoming messages automatically (using a live region). - Hides an editable area which isn't shown visually. + +### Telegram accessibility fixes +[Download Telegram Accessibility Fixes](https://github.com/nvaccess/axSGrease/raw/master/TelegramA11yFixes.user.js) + +This script improves the accessibility of the [Telegram instant messaging](https://web.telegram.org/) web interface. + +It so far does the following: + +- Marks the chat history as a live region so new messages are announced automatically.