Skip to content

Commit cad9c9e

Browse files
committed
Twitter: Use classList in onAttrModified, which is much more elegant than messing with the class string. In onFocus, kill an exception which occurs when focus hits the document.
1 parent e26ea6f commit cad9c9e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

TwitterA11yFixes.user.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ function onAttrModified(evt) {
1717
if (attrName != "class")
1818
return;
1919
var target = evt.target;
20-
var classes = target.getAttribute("class");
20+
var classes = target.classList;
2121
if (!classes)
2222
return;
23-
if (classes.indexOf(" stream-item") != -1) {
24-
if (classes.indexOf("hovered-stream-item") != -1) {
23+
if (classes.contains("stream-item")) {
24+
if (classes.contains("hovered-stream-item")) {
2525
// This tweet just got focus.
2626
// Twitter doesn't use real focus for this, so screen readers don't know which tweet has focus.
2727
// Force real focus.
@@ -39,7 +39,7 @@ function onAttrModified(evt) {
3939
+ orig.getElementsByClassName("time")[0].textContent
4040
));
4141
target.setAttribute("aria-expanded",
42-
(classes.indexOf(" open ") == -1) ? "false" : "true");
42+
(classes.contains("open")) ? "true" : "false");
4343
target.focus();
4444
} else
4545
lastFocusedTweet = null;
@@ -65,6 +65,8 @@ function onNodeRemoved(evt) {
6565
var idCounter = 0;
6666
function onFocus(evt) {
6767
var target = evt.target;
68+
if (target == document)
69+
return;
6870
var tag = target.tagName;
6971
var classes = target.getAttribute("class");
7072

0 commit comments

Comments
 (0)