Chrome扩展程序:在所有的Google网域和特定网页上运行 [英] Chrome extension: Run on all google domains and a specific page

查看:411
本文介绍了Chrome扩展程序:在所有的Google网域和特定网页上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



Manifest.json

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

....

有没有其他方法可以做到这一点?在列出Google所有域名之前,只想确定一下:) 列出所有Google域名并不困难,因为Google已在 http://www.google.com/supported_domains 发布了所有公开Goog​​le网域的列表。使用*:// * 为每个项目添加前缀,并为每个项目添加后缀。然后将结果复制粘贴到清单文件中。



另一种选择是使用 include_globs 字段(在matches之后应用):

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

js:[contentscript.js]
}]
}

(我已替换*://www.google.com/* 与*://*.google.com/* ,因为子域名如 https://encrypted.google.com/

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

解决方案

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

这篇关于Chrome扩展程序:在所有的Google网域和特定网页上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆