更改Chrome扩展程序中的页面样式表

Sus*_*tha 3 javascript google-chrome-extension

我试图做一个更改页面样式表的扩展名.我改变一些风格,如背景颜色,但我不能改变整个样式表

manifest.json文件

{
  "name": "change stylesheet",
  "version": "1.0",
  "permissions": [
    "tabs", "http://*/*", "https://*/*"
  ],
  "browser_action": {
      "default_title": "Set this page's style",
      "default_icon": "icon.png",
      "popup": "popup.html"
  }
}
Run Code Online (Sandbox Code Playgroud)

java脚本在popup.htm中调用的部分

function click() {
  chrome.tabs.executeScript(null,
      {code:"document.getElementById('stylesheet').href = 'style1.css'"});
  window.close();
}
Run Code Online (Sandbox Code Playgroud)

小智 7

Susantha - 你只需要在你的清单中包含你的css文件:

http://code.google.com/chrome/extensions/content_scripts.html

{
"name": "My extension",
 ...
  "content_scripts": [
{
  "matches": ["http://www.google.com/*"],
  "css": ["mystyles.css"],
  "js": ["jquery.js", "myscript.js"]
}
 ],
  ...
 }
Run Code Online (Sandbox Code Playgroud)

您将需要覆盖现有样式,!important并按照通常的方式遵循样式的先例.如果有内联样式,那么您可能需要使用js代码重写它.