From e62090838a2947922feac0fcf7075b5fde237996 Mon Sep 17 00:00:00 2001 From: Joe Lollo <53008442+ChessPiece21@users.noreply.github.com> Date: Tue, 31 Aug 2021 15:42:48 -0700 Subject: [PATCH] Easy inject method. --- src/inject/inject.js | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/inject/inject.js b/src/inject/inject.js index 3e114d5..7e7a3a6 100644 --- a/src/inject/inject.js +++ b/src/inject/inject.js @@ -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); + } + } } - -}); \ No newline at end of file +}