Modify script to select hidden layers/groups?
I found a script to select the previous layer and set it as visible. It works but I'd like to modify it slightly if possible.
At the moment if you start from the selected layer like so.

I'd like it so that each time the script is run it selects the previous layer/group and make it shown/visible like this.

But what currently happens with the script is that when it gets to a group is expands the folder and starts selecting layers inside the folder and turning on visibility.

Does anyone know how to modify the script (or use a different one) so that for groups it just turns the visibility on without expanding the group and selecting layers inside the groups?
Here's the current code:
// Select previous layer/group down & set to visible
var doc = app.activeDocument;
var cLayer = doc.activeLayer;
function activ (nLayer_f)
{
var check = nLayer_f.visible;
doc.activeLayer = nLayer_f;
if (check == false)
doc.activeLayer.visible = false;
}
var parL = doc.activeLayer.parent;
var parLln = parL.layers.length;
for(i=0; i<parLln;)
{
if(parL.layers==cLayer)
{
try
{
nLayer = cLayer.layers[0];
}
catch(e)
{
if(i!=parLln-1)
{
nLayer=parL.layers[i+1];
}
else
{
upmem = parL;
while (upmem!=doc && upmem.parent.layers[upmem.parent.layers.length-1]==upmem)
{
upmem = upmem.parent;
}
if (upmem==doc)
{
upmem=upmem.layers[0];
var lastmem = 1;
}
for(k=0;k<upmem.parent.layers.length;)
{
if(upmem.parent.layers
==upmem) {
aa=k;
if(lastmem==1)
{aa=-1;}
nLayer=upmem.parent.layers[aa+1];
k=upmem.parent.layers.length;
}
else {k++;}
}
}
}
activ (nLayer);
i=parLln-1;
}
i++;
}
// Show current layer
app.activeDocument.activeLayer.visible = true;
