如何在所有Google(国际)网页上加载内容脚本? [英] How to load a content script on all Google (international) pages?
问题描述
对于Google-Chrome扩展程序,我想在所有Google页面上加载内容脚本。什么是最好的方式做到这一点?
For a Google-Chrome extension, I would like to load a content script on all Google pages. What is the best way to do this?
我试过这个,在 manifest.json
中,但它确实不工作:
I tried this, in the manifest.json
, but it does not work:
"matches": ["http://www.google.*/*", "https://www.google.*/*"],
这个有效但它写了很长时间,我认为这不是最佳做法:
This "works" but it is a bit long to write and I do not think it is the best practice:
"matches": ["http://www.google.com/*", "https://www.google.com/*", "http://www.google.fr/*", "https://www.google.fr/*", "http://www.google.de/*", "https://www.google.de/*", etc..."],
推荐答案
请参阅 Match patterns and globs 。不幸的是,Google-Chrome对于顶级域名(顶级域名)在它的匹配
规范中,所以 http://www.google.*/*
会抛出一个错误,并且的http://www.google.tld/*
( Greasemonkey语法)不受支持。
See Match patterns and globs. Unfortunately, Google-Chrome doesn't have a nice mechanism for top-level-domains (TLD's) in its matches
specification. So, http://www.google.*/*
throws an error and http://www.google.tld/*
(Greasemonkey syntax) is not supported.
要解决此问题,请扩展匹配
参数,并使用 include_globs
参数过滤结果。
像这样:
To work around this, widen the matches
parameter and filter the results with the include_globs
parameter.
Like so:
"matches": ["http://*/*", "https://*/*"],
"include_globs": ["http://www.google.*/*", "https://www.google.*/*"],
这篇关于如何在所有Google(国际)网页上加载内容脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!