0

So I am currently making a google chrome extension, and what I am trying to do is copy one of my local CSS to the webpage, to replace it. This is what I have, but it's not copying them, but instead creating new files. How do I get this to copy my local file instead of create new ones?

function ChangeStyle(Style){
    var header =  document.getElementsByTagName("head")[0]
    var oringinal_link = document.getElementsByTagName("link")[0]
    oringinal_link.remove()
    if(Style === 1){
        $("head").prepend('<link rel="stylesheet" type="text/css" href="/default.css">')
    } else if(Style === 2){
        $("head").prepend('<link rel="stylesheet" type="text/css" href="/style1.css">')
    } else if(Style === 3){
        $("head").prepend('<link rel="stylesheet" type="text/css" href="/style2.css">')
    }
    console.log("[The Sustainer] Style " + Style + " has been loaded!")

This is my content.js file.

1
  • 1
    I do not understand the question. What do you mean by "copy" and "creating new files"? Commented Jun 20, 2016 at 9:40

1 Answer 1

1

You have to include the css file you want to upload in the manifest file as web accesible.

{ ...,   
  "web_accessible_resources": ["default.css", "style1.css", "style2.css"],
...}

Loading the css file can be done only in your content script.

Sign up to request clarification or add additional context in comments.

3 Comments

How would I be able to do that? >.< Sorry, I'm kind of new to creating extensions.
You can find the manifest.json file in your working folder. Append the above line in the root element.
Thanks so much! I would thumbs this up but I currently don't have enough rap :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.