aboutsummaryrefslogtreecommitdiff
path: root/src/content/follow.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-17 19:48:49 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-17 19:48:49 +0900
commit1880df95f60f1410a83b6af65ec9b8a74c2f59f2 (patch)
tree829eff07a3dff006ca5c3a98cbe4dd3af3697282 /src/content/follow.js
parent324cf32c5bd5d7e7ce89a9aaa7497454a7dfdbb2 (diff)
show hints for elements in viewport
Diffstat (limited to 'src/content/follow.js')
-rw-r--r--src/content/follow.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/content/follow.js b/src/content/follow.js
index f9cc380..7d69b45 100644
--- a/src/content/follow.js
+++ b/src/content/follow.js
@@ -124,13 +124,25 @@ export default class Follow {
return chars;
}
+ static inWindow(window, element) {
+ let {
+ top, left, bottom, right
+ } = element.getBoundingClientRect();
+ return (
+ top >= 0 && left >= 0 &&
+ bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
+ right <= (window.innerWidth || document.documentElement.clientWidth)
+ );
+ }
+
static getTargetElements(doc) {
let all = doc.querySelectorAll('a,button,input,textarea');
let filtered = Array.prototype.filter.call(all, (element) => {
let style = window.getComputedStyle(element);
return style.display !== 'none' &&
style.visibility !== 'hidden' &&
- element.type !== 'hidden';
+ element.type !== 'hidden' &&
+ Follow.inWindow(window, element);
});
return filtered;
}