I'm creating an extension for Chrome which will search for a certain phrase/word on the website. How can I do this with JavaScript? I tried many solutions I found on the Internet, but none of them works. Code: https://www.dropbox.com/sh/0d38od48qhpdhhf/AAD7sYee6KDa5jUD1TIgg0d4a?dl=0
https://jsfiddle.net/hm659mkd/1/ <div id="test"><h1>Some Stuff</h1></div> <div class="woot woory what">ok what now?</div> <div id="ok">findme i bet you cant!</div> HTML: var word = "findme", queue = [document.body], curr ; while (curr = queue.pop()) { if (!curr.textContent.match(word)) continue; for (var i = 0; i < curr.childNodes.length; ++i) { switch (curr.childNodes[i].nodeType) { case Node.TEXT_NODE : if (curr.childNodes[i].textContent.match(word)) { alert("Found!"); } break; case Node.ELEMENT_NODE : queue.push(curr.childNodes[i]); break; } } } Code (JavaScript):