Though I've had my fair share of experience with JS, I'm just wanting to make a quick Chrome Extension for personal use. Essentially, all I'm looking for is pulling all urls that fit a certain pattern - for example, test.example.com/abcdefg
and change them to test.newexample.com/abcdefg
. That way, when the page is loaded, I can click the URLs and be sent to the new page without any redirects. The catch is, however, that some page content is loaded dynamically, meaning you can load more entries of said URL without actually reloading the page and you run into issues with being able to convert those too.
Since I've never done this before, I'm not much further than my manifest.json:
{
"name": "Test",
"version": "1.0",
"description": "Test",
}
I also wrote up some basic code that I've used in the past for a firefox plugin, but the problem is actually implementing it into my chrome plugin and executing it.
self.port.on("getElements", function(tag) {
var links = document.getElementsByTagName(tag);
for (var i = 0; i < links.length; i++) {
if (links[i].href.indexOf("currentpage.com") == -1) {
links[i].href = links[i].href.replace("example.com","brandnewexample.com");
}
}
});
So, I guess my question is how I can tie the above code or something similar into the plugin in order to actually get my code to execute? My roadblock right now is getting as far as being able to test and utilize it - after that, troubleshooting and adjusting shouldn't be too big of a problem.