aboutsummaryrefslogtreecommitdiff
path: root/script.js
diff options
context:
space:
mode:
authorThottyottyotty <thot@thiic.cc>2023-05-18 16:09:09 -0700
committerThottyottyotty <thot@thiic.cc>2023-05-18 16:09:09 -0700
commite373fd0c009beed4cd78af78583bf71b425b118e (patch)
tree37dee738eb8c66fb0ed9de1992c4296287678bdd /script.js
parenta375acdd2635fdfeb3d77a0715b7df7e6350dd62 (diff)
rewrite uiElementIsVisible
rewrite visibility checking to be more generic/cleaner as well as add functionality to check if the element is scrolled on screen for more intuitive paste-target selection
Diffstat (limited to 'script.js')
-rw-r--r--script.js24
1 files changed, 11 insertions, 13 deletions
diff --git a/script.js b/script.js
index db4d9157..53390be3 100644
--- a/script.js
+++ b/script.js
@@ -92,19 +92,17 @@ document.addEventListener('keydown', function(e) {
* checks that a UI element is not in another hidden element or tab content
*/
function uiElementIsVisible(el) {
- let isVisible = !el.closest('.\\!hidden');
- if (!isVisible) {
- return false;
+ if (el === document) {
+ return true;
}
- while ((isVisible = el.closest('.tabitem')?.style.display) !== 'none') {
- if (!isVisible) {
- return false;
- } else if (el.parentElement) {
- el = el.parentElement;
- } else {
- break;
- }
- }
- return isVisible;
+ const computedStyle = getComputedStyle(el);
+ const isVisible = computedStyle.display !== 'none';
+
+ const clRect = el.getBoundingClientRect();
+ const windowHeight = window.innerHeight;
+ const onScreen = clRect.bottom > 0 && clRect.top < windowHeight;
+
+ if (!isVisible || !onScreen) return false;
+ return uiElementIsVisible(el.parentNode);
}