Chrome 清单 Google URL

Chrome manifest Google URL

我一直在寻找更好的选择,但似乎找不到更好的方法。

我当前的 Chrome 扩展清单有大约 300 行代码,其中包括这些类型的 URL。

   "http://www.google.com/webhp*", "https://www.google.com/webhp*",
    "http://www.google.ad/webhp*", "https://www.google.ad/webhp*",
    "http://www.google.ae/webhp*", "https://www.google.ae/webhp*",
    "http://www.google.com.af/webhp*", "https://www.google.com.af/webhp*",
    "http://www.google.com.ag/webhp*", "https://www.google.com.ag/webhp*",
    "http://www.google.com.ai/webhp*", "https://www.google.com.ai/webhp*",
    "http://www.google.am/webhp*", "https://www.google.am/webhp*",
    "http://www.google.co.ao/webhp*", "https://www.google.co.ao/webhp*",
    "http://www.google.com.ar/webhp*", "https://www.google.com.ar/webhp*",
    "http://www.google.as/webhp*", "https://www.google.as/webhp*",
    "http://www.google.at/webhp*", "https://www.google.at/webhp*",

我需要匹配 URL 的 运行 我的 https://www.google.com/ (exact), https://www.google.com/webph* (alternative for Google homepage) and https://www.google.com/search* 脚本(以匹配我想要的搜索选项卡:图片、视频、购物等)

主要问题在于我无法对域扩展名 (.com/.de/.org) 使用通配符。

一定有更好的方法吧?我当前的清单看起来像一场灾难。

我认为你总是需要在某个地方有你的 URL 规格,但是有一个选项可以通过将它移动到 JavaScript 来让它以更广泛的方式匹配,这给了你如果需要,可以选择将其从清单中移开。

在您的清单中,只需声明扩展以在所有 URL 上注入后台脚本:

"content_scripts": [{
   "matches": ["http://*/*", "https://*/*"]
}]

然后在你的后台脚本中,定义扩展应该在哪里工作,例如:

var match = 'www.google.';
var excludes = ['maps', 'whatever'];    

chrome.tabs.onUpdated.addListener(function(id, info, tab) {
    if (tab.status !== "complete"){
        return;
    } 
    if(tab.url.indexOf(match) !== -1 && excludes.indexOf(tab.url) === -1){
        // inject your script
        chrome.tabs.executeScript(tab.id, {"file": "myScript.js"});
    }
}