Skip to content

Commit 802cb04

Browse files
committed
Initial import of GitHubA11yFixes.
This marks comment and commit group headers as headings for accessibility.
1 parent ca16b5d commit 802cb04

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

GitHubA11yFixes.user.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)