所以我试图在我从Chrome扩展程序打开的新标签页上找到一些内容。扩展可以打开选项卡,但函数在脚本之前运行。我希望在加载选项卡后运行脚本或此函数。 这是我的manifest.json文件:
{
"name": "SwagBot",
"version": "0.0.1",
"manifest_version": 2,
"description": "The Offical SwagBot extension to cop your supreme!",
"browser_action":{
"default_popup":"popup.html"
},
"permissions": [
"https://*/*",
"http://*/*",
"storage",
"tabs",
"activeTab",
"webRequest",
"webRequestBlocking",
"webNavigation",
"declarativeContent"
]
}
这是我的javascript:
function findItem(){
allText = document.getElementsByClassName("name-link");
console.log('start');
for(i = 0; i < allText.length; i++){
if(i % 2 == 0){
names.push(allText[i].innerHTML);
}else{
colors.push(allText[i].innerHTML);
links.push(allText[i].href);
}
}
for(i = 0; i < names.length; i++){
if(names[i].indexOf(itemName) != -1){
name_flag = true;
console.log('here');
}
if(colors[i].indexOf(itemColor) != -1 && name_flag == true){
itemlink = links[i];
console.log(itemlink);
}
}
}
StartButton.addEventListener('click', function() {
chrome.storage.sync.get(["category",], function(items) {
index_url = "http://www.TEHWEBPAGEIWANT.com" + items.category;
console.log(index_url);
chrome.tabs.create({
url: index_url
});
});
chrome.tabs.onCreated.addListener(findItem);
});
});
非常感谢任何帮助,谢谢。 :)