我正在尝试使一个Chrome扩展,与内容脚本,只匹配谷歌图片搜索结果页面。
它们(据我所知)是由URL参数中的&tbm=isch标识的。但是,匹配模式似乎只在路径上有效。我该怎么做呢?
发布于 2012-11-25 10:45:50
有两种方法:
(1)可以使用the include_globs property in the manifest。像这样的东西应该是有效的:
{
"content_scripts": [ {
"exclude_globs": [ ],
"include_globs": [ "https://www.google.com/search*tbm=isch*" ],
"js": [ "YOUR_SCRIPT.user.js" ],
"matches": [ "https://www.google.com/search*"
]
} ],
... ...(2)您可以在内容脚本的顶部放置如下测试:
if ( ! /\btbm=isch\b/i.test (location.search) ) {
return;
}前者可能更有效,但可能更难调整。
您还可以使用这些方法的组合。
https://stackoverflow.com/questions/13543693
复制相似问题