I am trying to make a new Chrome extension, and I need the icon to automatically change like a gif with an array of images, and repeat forever. My problem is I can't get the Javascript loop to work. Here is what I've got:
var min = 1;
var max = 12;
var current = min;
if (current > max)
current = min;
}
var keep_switching_icon = true;
function rotateIcon()
{
if ( keep_switching_icon )
{
chrome.browserAction.setIcon({path:"icon" + current + ".png"});
current++;
window.setTimeout(rotateIcon, 300);
}
}
A few changes should be done:
current > max
should be moved inside the functionconsole.clear();
var min = 1;
var max = 12;
var current = min;
var keep_switching_icon = true;
function rotateIcon() {
if (keep_switching_icon) {
//chrome.browserAction.setIcon({path:"icon" + current + ".png"});
console.log(current);
if (current++ > max) {
current = min;
};
window.setTimeout(rotateIcon, 300);
}
}
rotateIcon();
Just instead of console.log(current)
, uncomment your chrome.browserAction
function call and delete the first line.