且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Chrome 扩展中使用内容脚本文件注入 CSS?

更新时间:2023-12-05 11:36:46

您可以添加到清单的权限字段;请参阅web_accessible_resources.因此,您可以将其添加到清单中:

You could add to the manifest's permissions field; See web_accessible_resources. So you would add this to the manifest:

    , "web_accessible_resources": [
        "fix.css"
    ]

另请参阅程序化注入".和 insertCSS().

对于大多数应用程序,忘记所有 createElement 代码,只需将 CSS 文件添加到清单:

For most applications, forget all that createElement code and just add the CSS file to the manifest:

"content_scripts": [
   {
      "matches":    ["http://www.google.com/*"],
      "css":        ["fix.css"],
      "js":         ["script.js"]
   }
],

虽然我知道你不想在这个确切的例子中这样做.

although I understand that you don't want to do that in this exact instance.