Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
La extensión de Chrome para reemplazar el texto en la página web solo funciona después de actualizar manualmente la página web a veces

Estoy desarrollando una extensión de Chrome para reemplazar textos específicos en la página web. Para algunos sitios web, solo funciona después de actualizar las páginas web manualmente con F5. Por ejemplo, cuando abro http://www.iciba.com/ e ingreso Google y presiono Enter, no se reemplazan todos los textos de Google en los resultados. Pero después de presionar F5 para actualizar la página manualmente, se reemplazan todos los textos.

manifiesto.json:

 { "name": "My Extension", "version": "0.1.0", "description": "An extension that replaces texts on webpages", "manifest_version": 2, "permissions": [ "tabs", "<all_urls>" ], "content_scripts": [{ "matches": [ "http://*/*", "https://*/*" ], "js": [ "replacetxt.js" ], "run_at": "document_end", "all_frames": true }] }

reemplazar txt.js:

 function isExcluded(elm) { if (elm.tagName == "STYLE") { return true; } if (elm.tagName == "SCRIPT") { return true; } if (elm.tagName == "NOSCRIPT") { return true; } if (elm.tagName == "IFRAME") { return true; } if (elm.tagName == "OBJECT") { return true; } return false } function traverse(elm) { if (elm.nodeType == Node.ELEMENT_NODE || elm.nodeType == Node.DOCUMENT_NODE) { // exclude elements with invisible text nodes if (isExcluded(elm)) { return } for (var i=0; i < elm.childNodes.length; i++) { // recursively call to traverse traverse(elm.childNodes[i]); } } if (elm.nodeType == Node.TEXT_NODE) { // exclude text node consisting of only spaces if (elm.nodeValue.trim() == "") { return } // elm.nodeValue here is visible text we need. console.log(elm.nodeValue); elm.nodeValue = elm.nodeValue.replace("Google", "***"); } } traverse(document);

Aquí están los códigos de trabajo siguiendo el consejo de @wOxxOm

 // Options for the observer (which mutations to observe) const config = { attributes: true, childList: true, subtree: true }; // Callback function to execute when mutations are observed const callback = function(mutationsList, observer) { // Use traditional 'for loops' for IE 11 for(const mutation of mutationsList) { traverse(mutation.target); } }; // Create an observer instance linked to the callback function const observer = new MutationObserver(callback); // Start observing the target node for configured mutations observer.observe(document, config);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

// Options for the observer (which mutations to observe) const config = { attributes: true, childList: true, subtree: true }; // Callback function to execute when mutations are observed const callback = function(mutationsList, observer) { // Use traditional 'for loops' for IE 11 for(const mutation of mutationsList) { traverse(mutation.target); } }; // Create an observer instance linked to the callback function const observer = new MutationObserver(callback); // Start observing the target node for configured mutations observer.observe(document, config);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!