Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using array to add extensibility and moved invocation to after function definition #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions Source/content_script.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
walk(document.body);

function walk(node)
{
// I stole this function from here:
// http://is.gd/mwZp7E

var child, next;

switch ( node.nodeType )
Expand All @@ -27,16 +25,32 @@ function walk(node)
}
}

function handleText(textNode)
{
var v = textNode.nodeValue;

v = v.replace(/\bThe Cloud\b/g, "My Butt");
v = v.replace(/\bThe cloud\b/g, "My butt");
v = v.replace(/\bthe Cloud\b/g, "my Butt");
v = v.replace(/\bthe cloud\b/g, "my butt");

textNode.nodeValue = v;
}


function handleText(textNode){
var textArray = [{
originalText: "The Cloud",
updatedText: "My Butt"
},{
originalText: "The cloud",
updatedText: "My butt"
}, {
originalText: "the Cloud",
updatedText: "my Butt"
}, {
originalText: "the cloud",
updatedText: "my butt",
}
];

for (var enumeration = textArray.length - 1; enumeration >= 0; enumeration--) {
// console.log(textArray[enumeration]);
var nodeTextToFix = textNode.nodeValue;

var huntedPhrase = new RegExp(textArray[enumeration].originalText, "g")


textNode.nodeValue = nodeTextToFix.replace(huntedPhrase, textArray[enumeration].updatedText);
};
}
walk(document.body);