MCPcopy
hub / github.com/liriliri/eruda / search

Function search

src/Snippets/defSnippets.js:163–192  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

161evalCss(require('./searchText.scss'), document.head)
162
163function search(text) {
164 const root = document.body
165 const regText = new RegExp(text, 'ig')
166
167 traverse(root, (node) => {
168 const $node = $(node)
169
170 if (!$node.hasClass('eruda-search-highlight-block')) return
171
172 return document.createTextNode($node.text())
173 })
174
175 traverse(root, (node) => {
176 if (node.nodeType !== 3) return
177
178 let val = node.nodeValue
179 val = val.replace(
180 regText,
181 (match) => `<span class="eruda-keyword">${match}</span>`
182 )
183 if (val === node.nodeValue) return
184
185 const $ret = $(document.createElement('div'))
186
187 $ret.html(val)
188 $ret.addClass('eruda-search-highlight-block')
189
190 return $ret.get(0)
191 })
192}
193
194function traverse(root, processor) {
195 const childNodes = root.childNodes

Callers 1

fnFunction · 0.85

Calls 4

traverseFunction · 0.85
htmlMethod · 0.80
textMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…