簡體   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