* @description: 遍历找出所有文本节点 * @param {*} node * @return {*} 节点map
(node)
| 302 | * @return {*} 节点map |
| 303 | */ |
| 304 | function textMap(node) { |
| 305 | // 存储文本节点 |
| 306 | let nodeMap = new Map() |
| 307 | |
| 308 | const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, (textNode) => { |
| 309 | if (textNode.parentElement.nodeName === 'SCRIPT' | |
| 310 | textNode.parentElement.nodeName === 'script' | |
| 311 | textNode.parentElement.nodeName === 'style' | |
| 312 | textNode.parentElement.nodeName === 'STYLE' | |
| 313 | textNode.parentElement.className === 'mt_highlight' | |
| 314 | document.querySelector('#mt_seting_box').contains(textNode) |
| 315 | ) { |
| 316 | return NodeFilter.FILTER_SKIP |
| 317 | } |
| 318 | |
| 319 | if (textNode.data.length < 20) { |
| 320 | return textNode.data.replace(/[\n \t]/g, '').length ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP |
| 321 | } |
| 322 | |
| 323 | return NodeFilter.FILTER_ACCEPT |
| 324 | }) |
| 325 | |
| 326 | while ((textNode = walker.nextNode())) { |
| 327 | nodeMap.set(textNode, textNode.data) |
| 328 | } |
| 329 | |
| 330 | return nodeMap |
| 331 | } |
| 332 | |
| 333 | // 高亮 |
| 334 | class HIGHTLIGHT { |
no outgoing calls
no test coverage detected