-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathReviewBoardA11yFixes.user.js
53 lines (49 loc) · 1.92 KB
/
ReviewBoardA11yFixes.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
// ==UserScript==
// @name Review Board Accessibility Fixes
// @namespace http://axSGrease.nvaccess.org/
// @description Improves the accessibility of Review Board.
// @author James Teh <[email protected]>
// @copyright 2016 NV Access Limited
// @license GNU General Public License version 2.0
// @version 2016.1
// @grant GM_log
// @include https://reviewboard.*/r/*/diff/*
// ==/UserScript==
function tweakSideBySide(side) {
// Make the diff file name into a heading instead of a table header.
// Among other things, this prevents it from being reported as a header for every cell.
var elem = side.querySelector('thead th');
if (elem) {
elem.setAttribute("role", "heading");
elem.setAttribute("aria-level", "2");
}
// Similarly, don't treat the revision cells as headers.
for (elem of side.querySelectorAll(".revision-col"))
elem.setAttribute("role", "cell");
// For changed lines, prefix the right hand line number with off-screen text indicating the type of change.
for (var tbody of side.querySelectorAll("tbody.insert,tbody.replace,tbody.delete")) {
for (var th of tbody.querySelectorAll("tr th:nth-child(3)"))
th.innerHTML = '<span style="position: absolute; left: -10000px;">' + tbody.className + '</span> ' + th.innerHTML;
}
}
function onNodeAdded(target) {
if (target.classList.contains("sidebyside"))
tweakSideBySide(target);
}
var observer = new MutationObserver(function(mutations) {
for (var mutation of mutations) {
try {
if (mutation.type === "childList") {
for (var node of mutation.addedNodes) {
if (node.nodeType != Node.ELEMENT_NODE)
continue;
onNodeAdded(node);
}
}
} catch (e) {
// Catch exceptions for individual mutations so other mutations are still handled.
GM_log("Exception while handling mutation: " + e);
}
}
});
observer.observe(document, {childList: true, subtree: true});