4

我希望我的内容脚本匹配所有 google 域和特定页面。我知道这是不可能的。

清单.json

"content_scripts": [{
        "matches": [
           ,"*://www.google.*"
           ,"*://www.youtube.com/*"
           ,"*://readthedocs.org/*"]
       ,
       ....

还有另一种方法可以做到这一点吗?只是想在我列出 Google 拥有的所有域之前确保 :)

4

1 回答 1

12

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.

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" ]
    }]
}

(I've replaced "*://www.google.com/*" with "*://*.google.com/*, because of subdomains like https://encrypted.google.com/)

于 2013-09-04T14:35:54.603 回答