Greasemonkey / Tampermonkey @match用于包含参数的页面 [英] Greasemonkey/Tampermonkey @match for a page with parameters
问题描述
我正在处理必须在某个页面中执行的脚本,具体取决于它具有的参数。网址如下:
I'm working on a script that must be executed in a certain page, depending on the parameters it has. The URL is like this:
http://example.com/page.php?key1=value1&key2=value2&...
我需要在 page.php时匹配它
其参数中包含 key1 = value1
。
And I need to match it when page.php
has the key1=value1
among its parameters.
现在我正在使用
@match http://example.com/page.php?key1=value1&*
但如果 page.php
没有其他参数,则不匹配。如果 key1
也不是第一个参数,它也将不匹配。
But it doesn't match if page.php
has no other parameters. It also won't match if key1
is not the first parameter either.
有没有办法匹配a页面根据参数?
Is there any way to match a page according to a parameter?
推荐答案
@match
only works on the protocol/scheme, host, and pathname of a URL.
要触发查询参数,您可以使用 @include
或使用 @match
并且还自己测试URL。
同时, @match
方法执行得更快。暂时没有测试过。
使用 @include
,你可以使用正则表达式语法。
To trigger off the query parameters, you can either use @include
or use @match
and also test the URL yourself.
At one time, the @match
approach performed faster. Haven't tested it in a while though.
With @include
, you can use a regex syntax.
请参阅包含和排除规则。
在这种情况下,请使用:
In this case, use either:
...
// @include /^http://example\.com/page\.php*key1=value1*/
// ==/UserScript==
或:
Or:
...
// @match http://example.com/page.php*
// ==/UserScript==
if (/\bkey1=value1\b/.test (location.search) ) {
// DO YOUR STUFF HERE.
}
这篇关于Greasemonkey / Tampermonkey @match用于包含参数的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!