获取Chrome pageAction图标以显示JSON中的URL列表
Get Chrome pageAction icon to appear for an URL list in JSON
我目前正在开发一个Chrome扩展,我希望pageAction图标显示大量URL(大约500个)。
在我的background.js文件(以及其他代码)中,我有这样的:
// Called when the url of a tab changes
function checkForValidUrl(tabId, changeInfo, tab) {
// If the tabs url starts with "http://specific_domain"
if (tab.url.indexOf('http://specific_domain') == 0) {
// Shows the page action
chrome.pageAction.show(tabId);
}
};
// Listen for any changes to the URL of any tab
chrome.tabs.onUpdated.addListener(checkForValidUrl);
我已经可以在特定网站上使用它了,但我想更改http://specific_domain'添加到允许的网站列表中,就像白名单一样。我可以访问一个联机的JSON文件。
这里有一个片段:
{
"antelife.com": {
"fbid": "AntElifecom",
"type": "store",
"name": "AntElife"
},
"amazon.com": {
"fbid": "Amazon",
"type": "store",
"name": "Amazon"
},
"ebay.com": {
"fbid": "eBay",
"type": "store",
"name": "eBay"
},
"mobilegeeks.com": {
"fbid": "mobilegeekscom",
"type": "publisher",
"name": "Mobile Geeks"
}
}
我想提取域,并以某种方式迭代所有域,如果它们在列表中,则应显示pageAction图标。类似这样的东西:
function checkForValidUrl(tabId, changeInfo, tab) {
for (var i = 0, iLength = whiteListUrl.length; i < iLength; i++) {
if (tab.url.indexOf('http://www.'+whiteListUrl[i]) > -1) {
chrome.pageAction.show(tabId);
notification.show();
break;
}
}
};
chrome.tabs.onUpdated.addListener(checkForValidUrl);
任何形式的帮助都应该是有用的。非常感谢。
如果你有一个json字符串,你可以通过这种方式获得url的列表;
var urlObj = JSON.parse(jsonString);
var whiteListUrl = Object.keys(urlObj);
相关文章:
- 区分JSON中的矩阵和列表列表
- 使用angularjs列出JSON中的字段值
- 通过JSON中的值增加
- 使用Angular显示JSON中的HTML
- 试图在Windows上执行package.json中的脚本会引发JScript错误
- 如何使用amcharts中的dataloader将对象加载为JSON中的数据字段
- 返回JSON中的下标
- 只将JSON中的属性加载到现有的javascript对象中,而不破坏方法
- 使用Angular.js解析JSON中的嵌套对象数组
- 使用angular显示复杂json中的列表
- JS/JON-通过JS访问JSON中的多个数组
- Javascript:获取 JSON 中的值计数
- 使用Javascript将Json中的unicode转换为HTML
- 如何将这些数据编码为JSON中的父/子结构
- 如何使用php以json中的数组形式返回mysql-select
- 将JSON中的时间转换为实际播放PHP的时间
- 使用车把仅为 JSON 中的特定键生成 DOM 内容
- 摆脱 JSON 中的双引号
- 无法找到在 YouTube API 中转义 json 中的引号的方法
- 替换 JSON 中的字符串