Comments (2)
来自3年后的回复,抱歉回复晚了一(hen)点(jiu)😅
今天终于是看了下文档,但我们是需要递归的,因为父元素有时会决定子元素是否需要继续遍历,或者是遍历的时候是否需要做特殊处理。所以好像没办法发挥TreeWalker的优势?
from eye_protector.
可以考虑不直接使用 nextNode()
, 而是通过使用 firstChild/nextSibling/parentNode
和 nextSibling()
的组合手动进行 deep first 的遍历,应该可以把父元素不断的 push/pop 到一个数组里。这样就可以访问父祖元素了。
类似:
parents = []
node = root
goUp = false
while (true) {
if (goUp) {
goUp = false
node = walker.parentNode()
if (!node) {
break;
} else {
parents.pop()
node = walker.nextSibling()
if (!node) {
goUp = true
continue
}
}
} else {
node = walker.firstChild()
if (!node) {
node = walker.nextSibling()
if (!node) {
goUp = true;
continue
}
} else {
parents.push(node.parentNode)
}
}
}
from eye_protector.
Related Issues (17)
- no effect on float left/right items? HOT 3
- 只修改各个层背景色 HOT 1
- 打开护眼模式后,禅道无法切换日期 HOT 3
- 建议出release,方便下载安装 HOT 4
- 更新Chrome 98之后,插件不再改变google docs文字页背景色了 HOT 2
- 最新版google搜索会出现文字看不清,github也会这样 HOT 4
- 希望忽略的节点类型可以在配置中自定义设置
- 希望背景色弹出选择对话框
- 在插件说明处追加使用说明
- 表格中的实线加载有问题,edge浏览器,这个是不是有办法可以解决?第一次加载进去 HOT 5
- Detection a bit too sensitive HOT 2
- 现在好像很多网站用这个插件都变不了色了 HOT 1
- 建议自定义文字颜色
- 非常棒的插件 HOT 1
- 希望增加仅当前页面启用选项 HOT 3
- 如果能支持泛域名匹配就好了
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eye_protector.