问题描述
我希望我的内容脚本匹配所有谷歌域和特定页面.我知道这是不可能的.
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 已在 http://www.google.com/supported_domains.使用 "*://*
> 为该列表中的每个项目添加前缀,并为每个项目添加 ",
后缀.然后将结果复制粘贴到您的清单文件中.
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.* 等顶级域匹配的内容脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!