Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
Chrome Extension Loop todas las palabras en la página web

Estoy creando una extensión de Chrome que debe repetir todas las palabras en una página web y reemplazarlas con imágenes. El problema es que no puedo entender correctamente todas las palabras. Este es el código que tengo hasta ahora. Estoy ejecutando esto en content.js.

 walk(document.body, /([^\s]+)/g); function walk(node, targetRe) { var child; switch (node.nodeType) { case 1: // Element for (child = node.firstChild; child; child = child.nextSibling) { walk(child, targetRe); } break; case 3: // Text node handleText(node, targetRe); break; } } function handleText(node, targetRe) { var match, targetNode, followingNode, wrapper; // Does the text contain our target string? // (This would be a regex test in your http://... case) match = targetRe.exec(node.nodeValue); if (match) { // Split at the beginning of the match targetNode = node.splitText(match.index); // Split at the end of the match. // match[0] is the full text that was matched. followingNode = targetNode.splitText(match[0].length); console.log(followingNode) // Wrap the target in an `a` element. // First we create the wrapper and insert it in front // of the target text. We use the first capture group // as the `href`. wrapper = document.createElement('img'); wrapper.style.backgroundColor = "yellow" wrapper.src = "fasd";//suche match targetNode.parentNode.insertBefore(wrapper, targetNode); // Now we move the target text inside it wrapper.appendChild(targetNode); // Clean up any empty nodes (in case the target text // was at the beginning or end of a text ndoe) if (node.nodeValue.length == 0) { node.parentNode.removeChild(node); } if (followingNode.nodeValue.length == 0) { followingNode.parentNode.removeChild(followingNode); } // Continue with the next match in the node, if any match = followingNode ? targetRe.exec(followingNode.nodeValue) : null; } }

Pero a veces solo coincide con la primera palabra de una oración y también devuelve mucha basura, como código. ¿Cómo puedo filtrar eso?

Gracias por tu ayuda

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda