This is pretty much a basic Javascript question even though it involves some Chrome Extension API.
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
//complete may fire multiple times per page update
var timer = 0, interval;
console.log(changeInfo.status);
clearInterval(interval);
interval = setInterval(function() {
if (timer == 5) {
console.log('here');
clearInterval(interval);
}
timer++;
}, 1000);
}
});
I think all my script does right now is delay everything. What I want it to do is every time a 'complete' status happens, I want to check for 5 seconds to go by and then log 'here'. If another 'complete' fires, I want to get rid of the previous timer and start a new one. Basically wait until all 'complete's are fired...I need help fixing my interval logic...