代码之家  ›  专栏  ›  技术社区  ›  Csa77 Bartosz Radaczyński

如何在chrome扩展中将同一个域与多个扩展匹配?

  •  0
  • Csa77 Bartosz Radaczyński  · 技术社区  · 6 年前

    所以,我正在开发一个chrome扩展,它需要在域中的任何站点上激活。 example.extension 哪里 extension 可以是任何东西( .com , .de 等等)。

    我有一个内容脚本, manifest.json 我将列出的所有域名依次包括:

    "content_scripts": [{
        "js": ["content.js"],
        "matches": ["https://www.example.com/*","https://www.example.de/*"]
      }]
    

    但是我怎么能写些符合的东西呢 example.* 而不是全部列举? 请注意,我尝试过类似的方法,但不起作用:

     "content_scripts": [{
        "js": ["content.js"],
        "matches": ["https://www.example*"]
      }]
    
    2 回复  |  直到 6 年前
        1
  •  1
  •   Boston Avila    6 年前

    include_globs here

        "content_scripts": [{
               "js": ["content.js"],
                "matches": [ "*://*/*" ],
                "include_globs": [
                    "*://*.example.*/*",
                ]
            }]
    

    URL www.example.*

    if (window.location.host.startsWith('www.example')){
       //content script code
    }
    
        2
  •  1
  •   Iván Nokonoko    6 年前

    chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
        if (changeInfo.status == 'complete' && tab.url.indexOf('https://www.example.') == 0){
            chrome.tabs.executeScript(tabId,{file:'content.js'});
        }
    });