简体   繁体   English

Firefox 扩展:在所有 web 页面上应用 content_scripts 但在特定 web 页面上应用 css?

[英]Firefox extension: apply content_scripts on all web pages but css on specific web page?

I have a Firefox extension where I want to apply contentScript.js to all web pages .我有一个Firefox扩展,我想在其中将contentScript.js应用于所有 web 页面 The manifest.json looks like this: manifest.json json 如下所示:

  "content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "css": ["background.css"],
      "js":["contentScript.js"]
    }
  ]

However, I only want the CSS to be applied to a certain web page.但是,我只想将CSS应用于某个web页面。 Right now the CSS is applied to all web pages.现在 CSS 应用于所有 web 页面。

How can I solve this?我该如何解决这个问题?

My friend came up with a solution, change your manifest file to this:我的朋友想出了一个解决方案,将您的清单文件更改为:

  "content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "js":["contentScript.js"]
    },
    {
      "matches": ["*://*.website.org/*"],
      "css": ["background.css"]
    }
  ]

Life saver.救生员。

暂无
暂无

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

相关问题 使用Web扩展的content_scripts中的ES模块(附加组件) - Use ES Modules from content_scripts of Web Extension (add-on) 在Firefox中与Web内容(页面对象)共享插件对象(内容脚本) - Sharing addon objects (content scripts) with Web content (page objects) in Firefox 如何从Chrome扩展程序的content_scripts中读取选项页中的配置集? - How to read configuration set in option page from content_scripts of Chrome extension? Google Chrome扩展程序 - content_scripts与background_page js文件进行通信 - Google Chrome Extension - content_scripts to communicate with background_page js files 如何让content_scripts在Chrome扩展程序的file:/// URL中执行 - How to get content_scripts to execute in file:/// URLs in a Chrome extension Chrome扩展程序 - 使用JQuery触发content_scripts上的事件 - Chrome Extension - Trigger events on content_scripts using JQuery 如何在Google扩展程序中打开/关闭content_scripts? - how do i toggle on/off content_scripts in a google extension? Chrome 扩展程序 - 从本地主机加载文件到 content_scripts - Chrome extension - loading file from localhost to content_scripts Firefox扩展中的“显示/隐藏”按钮在特定网页上不起作用 - Showing/Hiding button from firefox extension not working on specific web page 如何使用Firefox扩展将JavaScript函数注入到所有网页 - How to inject a JavaScript function to all web page using Firefox extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM