我需要在我的 chrome.declarativeContent.PageStateMatcher 中添加一些正则表达式。
到目前为止我有
var matcher = new chrome.declarativeContent.PageStateMatcher({
pageUrl: {
urlContains: "something.com/someRegex/something"
}
});
基本上我想要一个正则表达式来评估“something.com/4-5 char string/somithing”。
我该怎么做?这可能与 chrome.declarativeContent.PageStateMatcher 有关吗?
谢谢
最佳答案
而不是 urlContains 使用 urlMatches
这就是我在域 fedmich.com 和 fedche.com 上使用的内容
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlMatches: '(fedmich|fedche)\.com' },
})
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
});
});
文档在这里 https://developer.chrome.com/extensions/events#property-UrlFilter-hostEquals
正则表达式使用 RE2 语法。 https://code.google.com/p/re2/wiki/Syntax
关于javascript - chrome.declarativeContent.PageStateMatcher 中的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22309283/