I'm creating a chrome extension. It's a theme for a website and I'm making changes with css but also javascript. The javascript part simply exchanges a broken link with the working one and gives it another text. The code works on a fresh load of the page, but if I navigate to any other part of the site, it doesn't work anymore. It only starts working again when I reload, or upon opening a link in a new tab.
How can I change the code so it runs even after navigating to other parts of the site within the same tab?
var bookmarks = document.querySelector(".class li:nth-of-type(n) a");
bookmarks.innerHTML = "bookmarked";
bookmarks.href = "/user/bookmarks";
The queryselector stays the same after navigating, I tested it with css. I tried this next --
var bookmarks = document.querySelector(".class li:nth-of-type(n) a");
window.onload = function() {
bookmarks.innerHTML = "bookmarked";
bookmarks.href = "/user/bookmarks";
};
but to no avail. I'm really at a loss here as to what is going wrong.