如何在所有 Google(国际)页面上加载内容脚本? [英] How to load a content script on all Google (international) pages?

查看:23
本文介绍了如何在所有 Google(国际)页面上加载内容脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 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..."],

推荐答案

参见 匹配模式和全局.不幸的是,Google-Chrome 在其 matches 规范中没有很好的顶级域 (TLD) 机制.因此,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.

要解决此问题,请扩大 matches 参数并使用 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屋!

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