forked from jcsteh/axSGrease
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimplenoteA11yFixes.user.js
More file actions
73 lines (63 loc) · 2.12 KB
/
SimplenoteA11yFixes.user.js
File metadata and controls
73 lines (63 loc) · 2.12 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
// ==UserScript==
// @name Simplenote Accessibility Fixes
// @namespace http://axSGrease.nvaccess.org/
// @description Improves the accessibility of Simplenote.
// @author James Teh <jamie@nvaccess.org>
// @copyright 2015 NV Access Limited
// @license GNU General Public License version 2.0
// @version 2015.1
// @grant GM_log
// @include https://app.simplenote.com/
// ==/UserScript==
function init() {
var elem;
if (elem = document.querySelector(".notes")) {
// Notes list.
elem.setAttribute("role", "list region");
elem.setAttribute("aria-label", "Notes");
}
if (elem = document.querySelector(".note")) // The note itself.
elem.setAttribute("role", "main");
for (var elem of document.querySelectorAll(".button"))
elem.setAttribute("role", "button");
if (elem = document.querySelector(".searchfield")) // Search box.
elem.setAttribute("role", "search");
}
function onNodeAdded(target) {
var elem;
if (target.id === "details_form") {
// The Info screen just appeared.
// Focus the "Pin to top" check box (the first focusable item therein).
if (elem = document.getElementById("details_pinned_chk"))
elem.focus();
}
}
function onClassModified(target) {
var classes = target.classList;
if (!classes)
return;
if (classes.contains("button"))
target.setAttribute("aria-pressed", classes.contains("active") ? "true" : "false");
}
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);
}
} else if (mutation.type === "attributes") {
if (mutation.attributeName == "class")
onClassModified(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, {childList: true, attributes: true,
subtree: true, attributeFilter: ["class"]});
init();