manifest.json上的多个匹配项

时间:2017-12-27 05:11:48

标签: json google-chrome google-chrome-extension

我想在google.comtwitch.tv.上匹配我的Chrome扩展程序运行,我尝试了以下两种方式:

第一种方式:

 "content_scripts": [ {
        "exclude_globs":    [  ],
        "include_globs":    [ "*" ],
        "js":["jquery.user.js","h.js", "main.js"],
        "matches": ["*//google.com", "*//twitch.tv/"],
        "run_at": "document_end",
        "permissions":["tabs","<all_urls>"]

    } ],

第二种方式:

"content_scripts": [ {
    "exclude_globs":    [  ],
    "include_globs":    [ "*" ],
    "js":["jquery.user.js","h.js", "main.js"],
    "matches": ["*//google.com, *//twitch.tv/"],
    "run_at": "document_end",
    "permissions":["tabs","<all_urls>"]

} ],

我用引号将两者分开并且无法正常工作的方式,我没有将URL's分开的那个只运行了第一个URL(google)

那么有没有办法让它在两个URLs上运行?

谢谢!

2 个答案:

答案 0 :(得分:1)

permissions超出content_scriptstwitch.tv的匹配模式有一个额外的斜杠。试试*//*.twitch.tv

<强>的manifest.json

"content_scripts": [ {
        "js":["jquery.user.js","h.js", "main.js"],
        "matches": ["*//*.google.com", "*//*.twitch.tv"],
        "run_at": "document_end",
    } ],
"permissions":["tabs","<all_urls>"]

答案 1 :(得分:0)

  1. 如果您需要为这两个域加载conman js和css。

    &#34; content_scripts&#34;:[ {   &#34;匹配&#34;:[&#34; http://www.google.com/ &#34;,&#34; https://www.twitch.tv/ &#34;],   &#34; css&#34; :,   &#34; JS&#34 ;:   &#34; run_at&#34;:&#34; document_end&#34; //如果要在文档准备好后加载js和css,请添加此标记 } ],

  2. 如果您需要为每个域加载单独的css和js

    &#34; content_scripts&#34;:[     {       &#34;匹配&#34;:[&#34; http://www.google.com/ &#34;],       &#34; css&#34; :,       &#34; JS&#34 ;:       &#34; run_at&#34;:&#34; document_end&#34; //如果要在文档准备好后加载js和css,请添加此标记     },     {       &#34;匹配&#34;:[&#34; https://www.twitch.tv/ &#34;],       &#34; css&#34; :,       &#34; JS&#34 ;:       &#34; run_at&#34;:&#34; document_end&#34; //如果要在文档准备好后加载js和css,请添加此标记     }   ]

相关问题