-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
134 lines (126 loc) · 3.26 KB
/
background.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
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
/*
* AxSHammer
* Background script
*Author: James Teh <[email protected]>
* Copyright 2020-2024 James Teh
* License: GNU General Public License version 2.0
*/
const topMenu = browser.menus.create({
contexts: ["all"],
title: "A&xSHammer",
});
browser.menus.create({
parentId: topMenu,
title: "Expose completely inaccessible elements",
onclick: exposeCompletelyInaccessibleElements,
});
browser.menus.create({
parentId: topMenu,
title: "Kill all aria-&hidden",
onclick: killAllAriaHidden,
});
browser.menus.create({
parentId: topMenu,
title: "Kill all ARIA &live regions",
onclick: killAllAriaLive,
});
browser.menus.create({
parentId: topMenu,
title: "Kill all ARIA &applications",
onclick: killAllAriaApplication,
});
browser.menus.create({
parentId: topMenu,
title: "Kill all aria-la&bel",
onclick: killAllAriaLabel,
});
browser.menus.create({
parentId: topMenu,
title: "Kill all ARIA &roles",
onclick: killAllAriaRole,
});
browser.menus.create({
parentId: topMenu,
title: "No idea, do all the things",
onclick: runAll,
});
function exposeCompletelyInaccessibleElements(info, tab) {
browser.tabs.executeScript(tab.id, {
allFrames: true,
code: `
for (let el of document.body.querySelectorAll(":empty:not(input):not(textarea):not([aria-label])")) {
el.setAttribute("role", "button");
let label = typeof el.className == "string" ? el.className : null;
if (label) {
// Strip out useless Font Awesome stuff:
// fa- prefixes, but keep the rest (fa-foo becomes just foo); and
// far and fas classes.
label = label.replace(/\\bfa-|\\bfa[rs]?\\b/g, "");
}
if (label) {
el.setAttribute("aria-label", label);
}
el.setAttribute("data-axSHammer-exposedCompletelyInaccessibleElement",
"true");
}
`,
});
}
function killAllAriaHidden(info, tab) {
browser.tabs.executeScript(tab.id, {
allFrames: true,
code: `
for (let el of document.querySelectorAll("[aria-hidden]")) {
el.removeAttribute("aria-hidden");
}
`,
});
}
function killAllAriaLive(info, tab) {
browser.tabs.executeScript(tab.id, {
allFrames: true,
code: `
for (let el of document.querySelectorAll("[aria-live]")) {
el.removeAttribute("aria-live");
}
`,
});
}
function killAllAriaApplication(info, tab) {
browser.tabs.executeScript(tab.id, {
allFrames: true,
code: `
for (let el of document.querySelectorAll("[role=application]")) {
el.removeAttribute("role");
}
`,
});
}
function killAllAriaLabel(info, tab) {
browser.tabs.executeScript(tab.id, {
allFrames: true,
code: `
for (let el of document.querySelectorAll("[aria-label]")) {
el.removeAttribute("aria-label");
}
`,
});
}
function killAllAriaRole(info, tab) {
browser.tabs.executeScript(tab.id, {
allFrames: true,
code: `
for (let el of document.querySelectorAll("[role]")) {
el.removeAttribute("role");
}
`,
});
}
function runAll(info, tab) {
exposeCompletelyInaccessibleElements(info, tab);
killAllAriaHidden(info, tab);
killAllAriaLive(info, tab);
killAllAriaApplication(info, tab);
killAllAriaLabel(info, tab);
killAllAriaRole(info, tab);
}