-
Notifications
You must be signed in to change notification settings - Fork 17
/
MonorailA11yFixes.user.js
57 lines (50 loc) · 1.6 KB
/
MonorailA11yFixes.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// ==UserScript==
// @name Monorail Accessibility Fixes
// @namespace http://axSGrease.nvaccess.org/
// @description Improves the accessibility of Google Code.
// @author James Teh <[email protected]>
// @copyright 2016-2017 NV Access Limited
// @license GNU General Public License version 2.0
// @version 2017.1
// @include https://bugs.chromium.org/p/*/issues/*
// ==/UserScript==
function fixStar(node) {
node.setAttribute("aria-label", node.getAttribute("title"));
}
function makeHeading(elem, level) {
elem.setAttribute("role", "heading");
elem.setAttribute("aria-level", level);
}
function makeHeadings() {
// Title.
var elem = document.querySelector(".issueheader");
makeHeading(elem, 1);
// Comments.
for (elem of document.getElementsByClassName("issuecommentheader"))
makeHeading(elem, 2);
// Add a comment heading.
var elem = document.querySelector("#makechanges div.h4");
makeHeading(elem, 2);
}
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
try {
if (mutation.type === "attributes") {
if (mutation.attributeName == "src" && mutation.target.id == "star")
fixStar(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, {attributes: true,
subtree: true, attributeFilter: ["src"]});
function initial() {
var star = document.getElementById("star");
if (star)
fixStar(star);
makeHeadings();
}
initial();