指定userscript目标时,匹配路径,但忽略查询参数

Match the path but ignore query parameters when specifying userscript target

本文关键字:参数 查询 路径 userscript 目标 指定      更新时间:2023-09-26

我有一个脚本,我想在我的测试网站上与mydomain.com/test.html和任何进一步的页面上运行,例如具有额外GET查询的页面,如mydomain.com/test.html?a=1&b=2

你知道我该怎么做吗?

我更喜欢使用正则表达式来指定userscript目标。例如:

@include    /https?:(www'.)?'/'/example'.com'/index'.html'?x=y/

这将匹配:

  • httphttps,因为?s字符之后意味着不需要
  • www和非www变体(还是?,这次用于(www'.)组)
  • /index.html?x=y路径。甚至GET查询参数也会影响脚本

如果您想匹配任何GET查询,只需将x=y替换为.*?,这在正则表达式中意味着任何:

@include    /https?:(www'.)?'/'/example'.com'/index'.html'?.*?/