for(var i=activeDocument.layers.length-1;i>=0;i--){
var layer = activeDocument.layers[i];
if(!layer.visible){
layer.visible = true;
layer.remove();
}
}
for(var i=activeDocument.layers.length-1;i>=0;i--){
var layer = activeDocument.layers[i];
if(!layer.visible){
layer.visible = true;
layer.remove();
}
}