Chrome extension: Run on all google domains and a specific page

对着背影说爱祢 提交于 2019-11-26 09:55:34

问题


I want my content script to match all google domains, and a specific page. I know this is not possible.

Manifest.json

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

Is there another way to do this? Just wanted to make sure before I list all domains Google has :)


回答1:


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/)



来源:https://stackoverflow.com/questions/18613731/chrome-extension-run-on-all-google-domains-and-a-specific-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!