繁体   English   中英

如何为 URL 中的给定哈希触发 Chrome 扩展程序、内容脚本?

[英]How to trigger a Chrome extension, content-script for a given hash in the URL?

我的比赛计划:

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

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

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

请参阅内容脚本,匹配模式
匹配模式不对 URL 的 片段部分进行操作。

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM