与顶级域名(例如所有google)匹配的内容脚本.* [英] Content script matching top-level domains like all google.*
问题描述
我希望我的内容脚本匹配所有google域和一个特定页面.我知道这是不可能的.
I want my content script to match all google domains, and a specific page. I know this is not possible.
Manifest.json
Manifest.json
"content_scripts": [{
"matches": [
,"*://www.google.*"
,"*://www.youtube.com/*"
,"*://readthedocs.org/*"]
,
....
还有另一种方法吗?只是想确保在列出Google拥有的所有域之前:)
Is there another way to do this? Just wanted to make sure before I list all domains Google has :)
推荐答案
列出所有Google域并不困难,因为Google已在作为该列表中的每个项目的前缀,并为每个项目添加"
后缀.然后将结果复制粘贴到清单文件中.
Listing all Google domains is not that difficult, because Google has published a list of all public Google domains at http://www.google.com/supported_domains. Prefix every item in this list with "*://*
and add the ",
suffix to every item. Then copy-paste the result to your manifest file.
另一种选择是使用 "include_globs"
字段(在匹配"之后应用):
An alternative option is to use the "include_globs"
field (this is applied after "matches"):
{
....
"content_scripts": [{
"matches": [ "*://*/*" ],
"include_globs": [
"*://*.google.*/*",
"*://*.youtube.com/*",
"*://readthedocs.org/*"
],
"js": [ "contentscript.js" ]
}]
}
(我已将"*://www.google.com/*"
替换为"*://*.google.com/*
,因为子域名,例如 https://encrypted.google.com/)
(I've replaced "*://www.google.com/*"
with "*://*.google.com/*
, because of subdomains like https://encrypted.google.com/)
这篇关于与顶级域名(例如所有google)匹配的内容脚本.*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!