gpt4 book ai didi

google-chrome - 如何在扩展页面操作上添加更多链接

转载 作者:行者123 更新时间:2023-12-04 13:26:57 26 4
gpt4 key购买 nike

我正在开发一个仅适用于特定域的扩展页面操作,我可以向页面操作添加多个链接吗?我的 background.js 是这样的。

是否可以在 background.html 中为扩展页面操作添加更多链接?

//背景.js

chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {

chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlContains: 'www.exemple.com' },
})
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);

最佳答案

是的,您可以通过添加多个 PageStateMatcher 来为多个站点注册页面操作。 s 到 conditions 的列表.

chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostSuffix: 'example.com' }
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostSuffix: 'example.net' }
}),
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}]);
});
});

注意:我替换了 urlContains hostSuffix 因为您想在某些域上显示页面操作,而不是在 URL 包含网站主机的所有页面上显示(例如,您可能不想匹配 http://localhost/path/containing/www.example.com )。查看 UrlFilter type 的文档了解更多匹配页面的方法。

关于google-chrome - 如何在扩展页面操作上添加更多链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27254700/

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