Skip to content

Commit 00b6288

Browse files
committed
Initial import of MonorailA11yFixes.
This makes headings for the issue title, comments and add comment section, as well as making the starred status accessible.
1 parent 63ee7ec commit 00b6288

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

MonorailA11yFixes.user.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// ==UserScript==
2+
// @name Monorail Accessibility Fixes
3+
// @namespace http://axSGrease.nvaccess.org/
4+
// @description Improves the accessibility of Google Code.
5+
// @author James Teh <jamie@nvaccess.org>
6+
// @copyright 2016 NV Access Limited
7+
// @license GNU General Public License version 2.0
8+
// @version 2016.1
9+
// @include https://bugs.chromium.org/p/*/issues/*
10+
// ==/UserScript==
11+
12+
function fixStar(node) {
13+
node.setAttribute("role", "checkbox");
14+
node.setAttribute("aria-checked",
15+
(node.src.indexOf("star_on.gif") == -1) ? "false" : "true");
16+
}
17+
18+
function makeHeading(elem, level) {
19+
elem.setAttribute("role", "heading");
20+
elem.setAttribute("aria-level", level);
21+
}
22+
23+
function makeHeadings() {
24+
// Title.
25+
var elem = document.querySelector(".issueheader");
26+
makeHeading(elem, 1);
27+
28+
// Comments.
29+
for (elem of document.getElementsByClassName("issuecommentheader"))
30+
makeHeading(elem, 2);
31+
32+
// Add a comment heading.
33+
var elem = document.querySelector("#makechanges div.h4");
34+
makeHeading(elem, 2);
35+
}
36+
37+
var observer = new MutationObserver(function(mutations) {
38+
mutations.forEach(function(mutation) {
39+
try {
40+
if (mutation.type === "attributes") {
41+
if (mutation.attributeName == "src" && mutation.target.id == "star")
42+
fixStar(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, {attributes: true,
51+
subtree: true, attributeFilter: ["src"]});
52+
53+
fixStar(document.getElementById("star"));
54+
makeHeadings();

0 commit comments

Comments
 (0)