| | |
| | | } |
| | | } |
| | | |
| | | |
| | | function wrapText(text, context, wrapper = 'div') { |
| | | let c = context.textContent; |
| | | let index = c.indexOf(text); |
| | | console.log(context); |
| | | // h1, h2, h3, h4, h5, h6, p, code, a, |
| | | if (index >= 0) { |
| | | let stop = index + text.length; |
| | | let s = c.substring(index,stop); |
| | | let before = c.substring(0,index); |
| | | let after = c.substring(stop); |
| | | c = `${before}<${wrapper}>${s}</${wrapper}>${after}`; |
| | | context.textContent = c; |
| | | |
| | | function wrap() { |
| | | if (index >= 0) { |
| | | let stop = index + text.length; |
| | | let s = c.substring(index,stop); |
| | | let before = c.substring(0,index); |
| | | let after = c.substring(stop); |
| | | c = `${before}<${wrapper}>${s}</${wrapper}>${after}`; |
| | | context.textContent = c; |
| | | } |
| | | } |
| | | |
| | | const contents = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "code"]; |
| | | const attributes = ["href", "title", "class", "id"]; |
| | | const children = ["span", "em", "strong", "b", "a"]; |
| | | contents.forEach(function(c){ |
| | | const cs = elems(c); |
| | | if(cs.length) { |
| | | cs.forEach(function(cx){ |
| | | // console.log(cx); |
| | | // check if |
| | | // if has children |
| | | // check if childen is in children array above |
| | | // check if children contain attributes |
| | | // process before replacing |
| | | // else replace and move on |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | |
| | | const searchQuery = findQuery(); |
| | | // console.log(searchQuery); |
| | | // wrapText(searchQuery[0],main,'mark'); |
| | | // wrapText(searchQuery[1],main,'mark'); |
| | | wrapText(searchQuery[1],main,'mark'); |
| | | |
| | | window.addEventListener('load', () => search()); |