Skip to content

Commit 77d761b

Browse files
committed
GitHub: For lines of code that can be commented on, place the Add line comment button after the code instead of before for accessibility.
1 parent 1baae28 commit 77d761b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

GitHubA11yFixes.user.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ function onSelectMenuItemChanged(target) {
1919
target.setAttribute("aria-checked", target.classList.contains("selected") ? "true" : "false");
2020
}
2121

22+
// Used when we need to generate ids for ARIA.
23+
var idCounter = 0;
24+
2225
function onNodeAdded(target) {
2326
var elem;
2427
var res = document.location.href.match(/github.com\/[^\/]+\/[^\/]+\/([^\/]+)(\/?)/);
@@ -37,6 +40,20 @@ function onNodeAdded(target) {
3740
if (elem = target.querySelector(".commit-title"))
3841
makeHeading(elem, 2);
3942
}
43+
if (["pull", "commit"].indexOf(res[1]) >= 0 && res[2] == "/") {
44+
// Pull request or commit.
45+
// Lines of code which can be commented on.
46+
for (elem of target.querySelectorAll(".add-line-comment")) {
47+
// Put the comment button after the code instead of before.
48+
// elem is the Add line comment button.
49+
elem.setAttribute("id", "axsg-alc" + idCounter);
50+
// nextElementSibling is the actual code.
51+
elem.nextElementSibling.setAttribute("id", "axsg-l" + idCounter);
52+
// Reorder children using aria-owns.
53+
elem.parentNode.setAttribute("aria-owns", "axsg-l" + idCounter + " axsg-alc" + idCounter);
54+
++idCounter;
55+
}
56+
}
4057

4158
// Site-wide stuff.
4259
// Checkable menu items; e.g. in watch and labels pop-ups.

0 commit comments

Comments
 (0)