Skip to content

Commit

Permalink
Easy inject method.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeLollo21 authored Aug 31, 2021
1 parent e158f3a commit e620908
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions src/inject/inject.js
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);
}
}
}

});
}

0 comments on commit e620908

Please sign in to comment.