From cd707a5e589de18840d6d0b9a8ae27f68b869b41 Mon Sep 17 00:00:00 2001 From: Jeffrey Chen <78434827+TCOTC@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:12:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E6=90=9C=E7=B4=A2=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E9=A1=B5=E7=AD=BE=E4=B8=AD=E4=B8=8D=E5=8F=AF=E8=A7=86=E7=9A=84?= =?UTF-8?q?=E6=96=87=E6=9C=AC=20#4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.json | 2 +- src/Search.vue | 32 +++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/plugin.json b/plugin.json index 0339bf2..551cbaf 100644 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "name": "siyuan-plugin-hsr-mdzz2048-fork", "author": "TCOTC", "url": "https://github.com/TCOTC/siyuan-plugin-hsr-mdzz2048-fork", - "version": "0.1.2", + "version": "0.1.3", "minAppVersion": "2.9.8", "backends": ["windows", "linux", "darwin"], "frontends": ["desktop", "browser-desktop"], diff --git a/src/Search.vue b/src/Search.vue index 19156d6..3e5c5df 100644 --- a/src/Search.vue +++ b/src/Search.vue @@ -83,12 +83,38 @@ function highlightHitResult(value: string, change: boolean) { // 搜索并高亮 return false; } - // 判断元素是否可见 + // // 判断元素是否可见 + // function isElementVisible(element) { + // const style = window.getComputedStyle(element); + // return style.display !== 'none' && style.visibility !== 'hidden'; + // } +// 上面这个不行,改成下面这个试试: function isElementVisible(element) { - const style = window.getComputedStyle(element); - return style.display !== 'none' && style.visibility !== 'hidden'; + // 检查元素本身的可见性 + function checkVisibility(elm) { + const style = window.getComputedStyle(elm); + return style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0'; } + // 递归检查元素及其父元素 + function checkElementAndParents(elm) { + if (!elm || elm === document.body) { + // 到达document.body,结束递归 + return true; + } + if (!checkVisibility(elm)) { + // 如果元素本身不可见,返回false + return false; + } + // 递归检查父元素 + return checkElementAndParents(elm.parentNode); + } + + return checkElementAndParents(element); +} +// + + // 对每个符合条件的元素,首先检查它是否是已选元素的后代,如果不是,则使用 createTreeWalker 遍历其文本节点 elements.forEach(element => { // 检查当前元素是否是任何其他已选元素的后代