如何触发Chrome扩展程序,URL中给定散列的内容脚本? [英] How to trigger a Chrome extension, content-script for a given hash in the URL?

查看:123
本文介绍了如何触发Chrome扩展程序,URL中给定散列的内容脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的匹配方案:

 content_scripts:[
{
matches:[
https://stackoverflow.com/questions#epic*

js:[silly.js]
}
],

因此,如果用户转到网页(如 #epic 它会转到 https://stackoverflow.com/questions#epic ,但会在URL末尾有 #epic ,这会激活内容脚本 silly.js



这就是应该发生的事情,但这不起作用。 / p>

解决方案

请参阅内容脚本,匹配模式。匹配模式不适用于查询 fragment 部分。



限制内容脚本到给定的哈希,使用 include_globs 和/或 exclude_globs 属性

例如,在这种情况下,您可以使用:

 content_scripts:[{
matches:[
*:/ /stackoverflow.com/questions/*

include_globs:[*#epic *],
js:[silly.js]
}],


My matches scheme:

"content_scripts" : [
 {
   "matches" : [
     "https://stackoverflow.com/questions#epic*"
   ],
   "js" : ["silly.js"]
 }
],

So if the user went to a webpage (like https://stackoverflow.com/questions) then added #epic it would go to https://stackoverflow.com/questions#epic but would have #epic on the end of the URL, which would activate the content script silly.js.

That's what's supposed to happen, but that doesn't work.

解决方案

See Content scripts, Match Patterns. Match patterns do not operate on the query nor the fragment portions of a URL.

To restrict a content script to a given hash, use the include_globs and/or exclude_globs properties.

For example, in this case you might use:

"content_scripts" :     [ {
    "matches" :         [
        "*://stackoverflow.com/questions/*"
    ],
    "include_globs" :   ["*#epic*"],
    "js" :              ["silly.js"]
} ],

这篇关于如何触发Chrome扩展程序,URL中给定散列的内容脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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