CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Chrome Extensions Replacing Words With Others

  1. #1
    Join Date
    Oct 2015

    Chrome Extensions Replacing Words With Others

    Oh yes another amateur asking for help to the community!

    Basically I am trying to create a Chrome Extensions that replaces words with others.
    So for example: 'Strawberry contains lots of vitamins' should become 'Red contains lots of vitamins'
    The extensions is working (except on Google search) but I would like to be able to do two more things:

    - being able to replace more words
    - being able to style the new words (i.e. 'red')

    Below is my code.
    Huge huge Thank you for your time and help !


    var elements = document.getElementsByTagName('*');

    for (var i = 0; i < elements.length; i++) {
    var element = elements[i];

    for (var j = 0; j < element.childNodes.length; j++) {
    var node = element.childNodes[j];

    if (node.nodeType === 3) {
    var text = node.nodeValue;
    var replacedText = text.replace(/strawberry/g,'red');

    if (replacedText !== text) {
    element.replaceChild(document.createTextNode(replacedText), node);


    "manifest_version": 2,
    "name": "[your extension name here]",
    "description": "[your extension description here]",
    "version": "0.1",

    "browser_action": {
    "default_icon": "icon.png" },

    "content_scripts": [

    "matches": [
    "css": ["inject.css"
    "js": [
    "run_at": "document_end"

  2. #2
    Join Date
    Jun 1999
    Eastern Florida

    Re: Chrome Extensions Replacing Words With Others

    Try a javascript forum for javascript questions. java != javascript

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)