summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-05-21 22:44:22 -0700
committerAlex Yatskov <alex@foosoft.net>2017-05-21 22:44:22 -0700
commit84f5954ad52e82b795b1e493a9111355ddaa0f07 (patch)
tree6c108b2394803c6c3fb9a3b0a5a5434525ad9bb3
parent48f612bb9235abfbedab9679c8238cbaaeab2a58 (diff)
handle scanning text for janky websites better #23
-rw-r--r--ext/fg/js/source-range.js20
1 files changed, 17 insertions, 3 deletions
diff --git a/ext/fg/js/source-range.js b/ext/fg/js/source-range.js
index 58b6a415..95177f0b 100644
--- a/ext/fg/js/source-range.js
+++ b/ext/fg/js/source-range.js
@@ -84,8 +84,22 @@ class TextSourceRange {
}
static shouldEnter(node) {
+ if (node.nodeType !== 1) {
+ return false;
+ }
+
const skip = ['RT', 'SCRIPT', 'STYLE'];
- return !skip.includes(node.nodeName);
+ if (skip.includes(node.nodeName)) {
+ return false;
+ }
+
+ const style = window.getComputedStyle(node);
+ const hidden =
+ style.visibility === 'hidden' ||
+ style.display === 'none' ||
+ parseFloat(style.fontSize) === 0;
+
+ return !hidden;
}
static seekForward(node, offset, length) {
@@ -106,7 +120,7 @@ class TextSourceRange {
}
static seekForwardHelper(node, state) {
- if (node.nodeType === 3) {
+ if (node.nodeType === 3 && node.parentElement && TextSourceRange.shouldEnter(node.parentElement)) {
const offset = state.node === node ? state.offset : 0;
const remaining = node.length - offset;
const consumed = Math.min(remaining, state.remainder);
@@ -143,7 +157,7 @@ class TextSourceRange {
}
static seekBackwardHelper(node, state) {
- if (node.nodeType === 3) {
+ if (node.nodeType === 3 && node.parentElement && TextSourceRange.shouldEnter(node.parentElement)) {
const offset = state.node === node ? state.offset : node.length;
const remaining = offset;
const consumed = Math.min(remaining, state.remainder);