简体   繁体   English

如何更改后台文件(Chrome扩展程序)中的content_scripts?

[英]How to change the content_scripts in background file (Chrome Extensions)?

How can i change the CSS file declared in content_scripts (manifest.json)? 如何更改content_scripts(manifest.json)中声明的CSS文件?
I need to change it from background.js (style.css to style2.css) 我需要将其从background.js(style.css更改为style2.css)
Is it possible to do that? 有可能这样做吗?
The manifest.json: manifest.json:

 { "manifest_version": 2, /* ... */ /* ... */ "background": { "scripts": [ "files/script/jquery-3.2.1.min.js", "files/script/background.js" ] }, "permissions": [ "tabs", "http://*/*", "https://*/*", "background", "browsingData", "cookies", "webRequest", "management", "storage" ], "content_scripts": [{ "matches": ["*"], "css": [ "files/css/style.css" ] }] } 

You cannot change declared CSS in the manifest file. 您不能在清单文件中更改声明的CSS。
But in order to run custom CSS programmatically from background script, you can use chrome.tabs.insertCSS . 但是为了从后台脚本以编程方式运行自定义CSS,可以使用chrome.tabs.insertCSS

// use a file
chrome.tabs.insertCSS({file: "style2.css"});

// use a CSS string
chrome.tabs.insertCSS({code: "body { background: red }" });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM