如何触发一个Chrome扩展,内容脚本在URL中的给定哈希

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

本文关键字:URL 脚本 哈希 何触发 扩展 Chrome 一个      更新时间:2023-09-26

我的匹配方案:

"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"]
} ],