View Single Post
Old 01-31-2018, 03:05 AM  
deonbell
Confirmed User
 
deonbell's Avatar
 
Industry Role:
Join Date: Sep 2015
Posts: 1,045
I did not write this. I copy from internet.
For Chrome, Replaces Trump everywhere in browser

content.js

Code:
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(/Trump/gi, '[avoidthis]');

            if (replacedText !== text) {
                element.replaceChild(document.createTextNode(replacedText), node);
            }
        }
    }
}
manifest.json
Code:
{
"manifest_version": 2,
    "name": "[goodbyelosers]",
    "description": "[replaces trump with avoidthis]",
    "version": "1.0",
    "content_scripts": [
        {
            "matches": [
                "*://*/*"
            ],
            "js": [
                "content.js"
            ],
            "run_at": "document_end"
        }
    ]
}
readme.md
Code:
This is your Chrome extension which replaces a word or phrase with a different word or phrase.
deonbell is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote