|
| 1 | +// ==UserScript== |
| 2 | +// @name GitHub Accessibility Fixes |
| 3 | +// @namespace http://axSgrease.nvaccess.org/ |
| 4 | +// @description Improves the accessibility of GitHub. |
| 5 | +// @author James Teh <jamie@nvaccess.org> |
| 6 | +// @copyright 2015 NV Access Limited |
| 7 | +// @license GNU General Public License version 2.0 |
| 8 | +// @version 2015.2 |
| 9 | +// @grant GM_log |
| 10 | +// @include https://github.com/* |
| 11 | +// ==/UserScript== |
| 12 | + |
| 13 | +function makeHeading(elem, level) { |
| 14 | + elem.setAttribute("role", "heading"); |
| 15 | + elem.setAttribute("aria-level", level); |
| 16 | +} |
| 17 | + |
| 18 | +function tweak(target) { |
| 19 | + var res = document.location.href.match(/github.com\/[^\/]+\/[^\/]+\/([^\/]+)(\/?)/); |
| 20 | + if (["issues", "pull"].indexOf(res[1]) >= 0 && res[2] == "/") { |
| 21 | + // Issue or pull request. |
| 22 | + // Comment headers. |
| 23 | + for (elem of target.querySelectorAll(".timeline-comment-header-text, .discussion-item-header")) |
| 24 | + makeHeading(elem, 3); |
| 25 | + } else if (res[1] == "commits" && res[2] == "/") { |
| 26 | + // Commits. |
| 27 | + // Commit group headers. |
| 28 | + for (elem of target.querySelectorAll(".commit-group-title")) |
| 29 | + makeHeading(elem, 2); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +var observer = new MutationObserver(function(mutations) { |
| 34 | + for (var mutation of mutations) { |
| 35 | + try { |
| 36 | + if (mutation.type === "childList") { |
| 37 | + for (var node of mutation.addedNodes) { |
| 38 | + if (node.nodeType != Node.ELEMENT_NODE) |
| 39 | + continue; |
| 40 | + tweak(node); |
| 41 | + } |
| 42 | + } |
| 43 | + } catch (e) { |
| 44 | + // Catch exceptions for individual mutations so other mutations are still handled. |
| 45 | + GM_log("Exception while handling mutation: " + e); |
| 46 | + } |
| 47 | + } |
| 48 | +}); |
| 49 | +observer.observe(document, {childList: true, subtree: true}); |
| 50 | + |
| 51 | +tweak(document); |
0 commit comments