|
| 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(); |
0 commit comments