Skip to content

Commit

Permalink
不搜索当前页签中不可视的文本 #4
Browse files Browse the repository at this point in the history
  • Loading branch information
TCOTC committed Mar 27, 2024
1 parent 71648ba commit cd707a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
32 changes: 29 additions & 3 deletions src/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
// 检查当前元素是否是任何其他已选元素的后代
Expand Down

0 comments on commit cd707a5

Please sign in to comment.