gpt4 book ai didi

javascript - Greasemonkey/Tampermonkey @match 带参数的页面

转载 作者:行者123 更新时间:2023-12-03 00:01:07 26 4
gpt4 key购买 nike

我正在编写一个必须在特定页面中执行的脚本,具体取决于它具有的参数。网址是这样的:

http://example.com/page.php?key1=value1&key2=value2&...

page.php 的参数中有 key1=value1 时,我需要匹配它。

现在我正在使用

@match http://example.com/page.php?key1=value1&*

但如果 page.php 没有其他参数,则不匹配。如果 key1 也不是第一个参数,它也不会匹配。

有没有办法根据参数来匹配页面?

最佳答案

@match only works on the protocol/scheme, host, and pathname of a URL.

要触发查询参数,您可以使用 @include 或使用 @match 并自行测试 URL。
请注意,@match 方法执行速度更快。

通过@include,您可以使用正则表达式语法。另请参阅Include and exclude rules .

在这种情况下,请使用任一:

...
// @include /^https?://example\.com/page\.php*key1=value1*/
// ==/UserScript==

**或者:**
...
// @match *://example.com/page.php*
// ==/UserScript==

if (/\bkey1=value1\b/.test (location.search) ) {
// DO YOUR STUFF HERE.
}

关于javascript - Greasemonkey/Tampermonkey @match 带参数的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20462544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com