-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e158f3a
commit e620908
Showing
1 changed file
with
13 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,18 @@ | ||
chrome.extension.sendMessage({}, function(response) { | ||
var readyStateCheckInterval = setInterval(function() { | ||
if (document.readyState === "complete") { | ||
clearInterval(readyStateCheckInterval); | ||
var elements = document.getElementsByTagName('*'); | ||
|
||
main(); | ||
} | ||
}, 10); | ||
|
||
function main() { | ||
// Replace page title | ||
document.title = generateReplacment(document.title); | ||
for (var i = 0; i < elements.length; i++) { | ||
var element = elements[i]; | ||
|
||
// Get all text nodes to check | ||
var textNodes = $('body *').contents().filter(function() { | ||
return this.nodeType == Node.TEXT_NODE; | ||
}); | ||
for (var j = 0; j < element.childNodes.length; j++) { | ||
var node = element.childNodes[j]; | ||
|
||
// Replace all text nodes | ||
textNodes.each(function(index, textNode) { | ||
textNode.nodeValue = generateReplacment(textNode.nodeValue); | ||
}); | ||
} | ||
if (node.nodeType === 3) { | ||
var text = node.nodeValue; | ||
var replacedText = text.replace(/algebra/gi, 'Al-Jazeera'); | ||
|
||
function generateReplacment(text) { | ||
var regex1 = /algebra/; | ||
return text.replace(regex1, replace("algebra", "Al-Jazeera")); | ||
if (replacedText !== text) { | ||
element.replaceChild(document.createTextNode(replacedText), node); | ||
} | ||
} | ||
} | ||
|
||
}); | ||
} |