aboutsummaryrefslogtreecommitdiff
path: root/script.js
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2023-05-19 09:53:02 +0300
committerGitHub <noreply@github.com>2023-05-19 09:53:02 +0300
commitfe7bcbe340d242560d9818411162206a12e3a146 (patch)
tree96a7a78340d9956ebcf5b260c8218e61e6878ee0 /script.js
parent8c1148b9ea439d4446437a6cd431cb6a73cd8a76 (diff)
parent7b61acbd35e9db43a5279a42afad3f3dc68462c9 (diff)
Merge pull request #10534 from thot-experiment/dev
rewrite uiElementIsVisible
Diffstat (limited to 'script.js')
-rw-r--r--script.js28
1 files changed, 15 insertions, 13 deletions
diff --git a/script.js b/script.js
index db4d9157..f7612779 100644
--- a/script.js
+++ b/script.js
@@ -92,19 +92,21 @@ 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';
+
+ if (!isVisible) return false;
+ return uiElementIsVisible(el.parentNode);
+}
+
+function uiElementInSight(el) {
+ const clRect = el.getBoundingClientRect();
+ const windowHeight = window.innerHeight;
+ const isOnScreen = clRect.bottom > 0 && clRect.top < windowHeight;
+
+ return isOnScreen;
}