dimanche 4 juillet 2021

How to make content scirpt rerun whenever I click anything

So I have a content script that adds some custom css to every element, but it only run's when I refresh the page. For Example when I'm on youtube the css is applied but when I click on a video the css on the navbar is still applied, but all the new stuff that was loaded does not have the custom css. Does anyone know how to fix this?

Manifest.json:

{
  "name": "Web redesigner",
  "version": "1.0",
  "description": "Hopefully works",
  "manifest_version": 2,
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "web_accessible_resources": [
    "test.css"
  ],
  "content_scripts": [
   {
     "matches": ["*://*/*"],
     "css": ["test.css"],
     "js": ["test.js"]
   }
 ]
}

test.js:

let elements = document.querySelectorAll("*"), // finds every element
  len = elements !== null ? elements.length : 0,
  i = 0;
for (i; i < len; i++) {
  elements[i].className += " custom-class"; // adds class "custom-class" to everything
}



Aucun commentaire:

Enregistrer un commentaire