- Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathGreenhouseA11yFixes.user.js
More file actions
Latest commit
154 lines (135 loc) · 4.45 KB
/
Copy pathGreenhouseA11yFixes.user.js
File metadata and controls
154 lines (135 loc) · 4.45 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// ==UserScript==
// @name Greenhouse Accessibility Fixes
// @namespace http://axSgrease.nvaccess.org/
// @description Improves the accessibility of Greenhouse.
// @author James Teh <jteh@mozilla.com>
// @copyright 2019 Mozilla Corporation
// @license Mozilla Public License version 2.0
// @version 2019.1
// @grant GM_log
// @include https://*.greenhouse.io/*
// ==/UserScript==
/*** Functions for common tweaks. ***/
functionmakeHeading(el,level){
el.setAttribute("role","heading");
el.setAttribute("aria-level",level);
}
functionmakeRegion(el,label){
el.setAttribute("role","region");
el.setAttribute("aria-label",label);
}
functionmakeButton(el,label){
el.setAttribute("role","button");
el.setAttribute("aria-label",label);
}
functionmakePresentational(el){
el.setAttribute("role","presentation");
}
functionsetLabel(el,label){
el.setAttribute("aria-label",label);
}
functionmakeHidden(el){
el.setAttribute("aria-hidden","true");
}
functionsetExpanded(el,expanded){
el.setAttribute("aria-expanded",expanded ? "true" : "false");
}
/*** Code to apply the tweaks when appropriate. ***/
functionapplyTweak(el,tweak){
if(Array.isArray(tweak.tweak)){
let[func, ...args]=tweak.tweak;
func(el, ...args);
}else{
tweak.tweak(el);
}
}
functionapplyTweaks(root,tweaks,checkRoot){
for(lettweakoftweaks){
for(letelofroot.querySelectorAll(tweak.selector)){
applyTweak(el,tweak);
}
if(checkRoot&&root.matches(tweak.selector)){
applyTweak(root,tweak);
}
}
}
letobserver=newMutationObserver(function(mutations){
for(letmutationofmutations){
try{
if(mutation.type==="childList"){
for(letnodeofmutation.addedNodes){
if(node.nodeType!=Node.ELEMENT_NODE){
continue;
}
applyTweaks(node,DYNAMIC_TWEAKS,true);
}
}elseif(mutation.type==="attributes"){
applyTweaks(mutation.target,DYNAMIC_TWEAKS,true);
}
}catch(e){
// Catch exceptions for individual mutations so other mutations are still handled.
GM_log("Exception while handling mutation: "+e);
}
}
});
functioninit(){
applyTweaks(document,LOAD_TWEAKS,false);
applyTweaks(document,DYNAMIC_TWEAKS,false);
observer.observe(document,{childList: true,attributes: DYNAMIC_TWEAK_ATTRIBS.length>0,
subtree: true,attributeFilter: DYNAMIC_TWEAK_ATTRIBS});
}
/*** Define the actual tweaks. ***/
functionlabelRating(el,ratingText){
letname=el.getAttribute("title");
setLabel(el,name+": "+ratingText);
}
// Tweaks that only need to be applied on load.
constLOAD_TWEAKS=[
{selector: '.tabs-nav',
tweak: el=>el.setAttribute("role","tablist")},
{selector: '.tabs-nav > li',
tweak: makePresentational},
];
// Attributes that should be watched for changes and cause dynamic tweaks to be
// applied. For example, if there is a dynamic tweak which handles the state of
// a check box and that state is determined using an attribute, that attribute
// should be included here.
constDYNAMIC_TWEAK_ATTRIBS=["class"];
// Tweaks that must be applied whenever a node is added/changed.
constDYNAMIC_TWEAKS=[
{selector: '.thumbs-up:not(.rating-with-name)',
tweak: [labelRating,"thumbs up"]},
{selector: '.two-thumbs-up:not(.rating-with-name)',
tweak: [labelRating,"two thumbs up"]},
{selector: '.mixed-rating:not(.rating-with-name)',
tweak: [labelRating,"mixed"]},
{selector: '.tabs-nav a',
tweak: el=>{
el.setAttribute("role","tab");
letselected=el.parentElement.classList.contains("selected");
el.setAttribute("aria-selected",selected ? "true" : "false");
}},
{selector: '.closed',
tweak: [setExpanded,false]},
{selector: '.open',
tweak: [setExpanded,true]},
{selector: '.scorecard-attributes-table .name.focus',
tweak: el=>{
// Importance is only indicated through colour.
// We can't just set aria-label here because it doesn't replace the content
// for table cells.
// Therefore, create a visually hidden indicator.
letimportant=document.createElement("span");
important.style="position: absolute; left: -1000px; width: 1px; height: 1px;";
important.setAttribute("aria-label","important");
el.insertBefore(important,el.firstChild);
}},
{selector: '.selectable',
tweak: el=>{
el.setAttribute("role","radio");
letchecked=el.classList.contains("selected");
el.setAttribute("aria-checked",checked ? "true" : "false");
}},
];
/*** Lights, camera, action! ***/
init();