我正在处理一个必须在某个页面中执行的脚本,这取决于它所具有的参数。URL如下所示:
http://example.com/page.php?key1=value1&key2=value2&...
当page.php
的参数中有key1=value1
时,我需要匹配它。
现在我正在使用
@match http://example.com/page.php?key1=value1&*
但是如果page.php
没有其他参数,它就不匹配。如果key1
不是第一个参数,它也不会匹配。
有没有办法根据参数匹配页面?
发布于 2013-12-09 12:40:24
@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.
}
发布于 2013-12-09 11:37:00
根据@match
的文档,查询字符串参数似乎不是Greasemonkey引擎可以匹配的内容:
https://stackoverflow.com/questions/20462544
复制相似问题