I'm trying to develop an extension for Chrome, and I'm still getting started, and right from the start I'm already stuck. I know very little of javascript but I try to do what I can by searching. This extension is inspired by FoxReplace from firefox , that is, an extension that searches for all user-designated entries on the page which is and replaces with any other text that the user places.
I found an extension for Chrome in github and used it as a reference, but because it is hyper simple (just get "The Cloud" and replace with "my butt" - yes, it's really rough), you can not follow much, besides the code written there I still do not I can interpret very well to be able to put what I intend.
What I've tried (from scratch):
I put:
var str = "Texto da substituição";
var res = str.replace(/Será substituído/gim,"Substituirá");
But it does not work the way I wanted it, because in addition to this, I only look for the term within "Substitution Text", instead of the whole document, it needs something to start the search for the terms, which I several sites, but all I found were codes to put directly in the HTML of the page, in the body
tag, which I think, if I'm not wrong, would not have contact with the extension, because it is part of the page and not application.
The extension that I took uses walk(document.body)
and then sets the walk(node)
function to the "statement" switch (node.nodeType)
, which from what I saw works the way expected, but it needs several fixes because it fails in many different situations.
So I would like someone to explain to me the operation of walk
, switch
and case
s the way they were used, and / or tell me how to do that which I intend in a more appropriate for my intention.
This extension I got, having edited with what I know, works fine, the problem is the bugs and some inexplicable things that happen with his main code, which I can only correct, perhaps, when I understand the content .