Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome extension 高效地添加规则_Google Chrome Extension - Fatal编程技术网

Google chrome extension 高效地添加规则

Google chrome extension 高效地添加规则,google-chrome-extension,Google Chrome Extension,在background.js中,我使用规则,但我也多次使用regex。我有基于这些规则的declarativeContent.ShowPageAction new chrome.declarativeContent.PageStateMatcher({pageUrl: { urlMatches: 'https?:\/\/([a-z0-9]+[.])*microsoft.com'},}), new chrome.declarativeContent.PageStateMatcher({pageUr

在background.js中,我使用规则,但我也多次使用regex。我有基于这些规则的declarativeContent.ShowPageAction

new chrome.declarativeContent.PageStateMatcher({pageUrl: { urlMatches: 'https?:\/\/([a-z0-9]+[.])*microsoft.com'},}),
new chrome.declarativeContent.PageStateMatcher({pageUrl: { urlMatches: 'https?:\/\/([a-z0-9]+[.])*google.com'},}),
new chrome.declarativeContent.PageStateMatcher({pageUrl: { urlMatches: 'https?:\/\/([a-z0-9]+[.])*amazon.com'},}),
有没有一种方法可以只使用一次正则表达式,并像在javascript中一样使用它

myRegexInstance.test(collectionOfURLs);

不要使用regexp。它们的速度很慢,而且您正在复制API已经执行的作业:它已经将URL分成了几个部分,您可以单独测试这些部分

使用主机后缀:

[
“.microsoft.com”,
“.google.com”,
“.amazon.com”,
].map(s=>new chrome.declarativeContent.PageStateMatcher({pageUrl:{hostSuffix:s}))
前导点将同时匹配
*://google.com/
和任何子域,例如
*://www.google.com/