Can I auto-expand a bunch of Javascript message toggles
March 7, 2009 3:19 PM   RSS feed for this thread Subscribe

I'm trying to archive, in PDF form, a series of Web pages where the content won't expand unless I click "more" dozens and dozens of times to reveal each hidden item. Is there some time-saving Firefox add on--or other tool--that could do this for me automatically? It's a Javascript thing...

In code terms, the full content is all there in the source code (maybe I ought to just give up and save as HTML--what do you think?) but hidden via a Javascript gimmick.

Each of the many items on the page is concealed from view using a Javascript "onClick" attached to the links. When you click the link it runs a .js script called "toggleMessage," which gets the ID# of the item and then opens it. What I am envisioning is some sort of Firefox Web designer plugin where I could tell it the name of the script and it would go run it for me, expanding every panel.

Is this something Firebug, for example, would do?

Here's the script.

function toggleMessage(id)
{
var span = document.getElementById('msg'+id);
if (span.style.display == 'none')
{
// hide the more link
document.getElementById('msglink'+id).style.display='none';
// show the div
span.style.display = 'inline';
// show the less link
document.getElementById('msglesslink'+id).style.display='inline';
// switch the image
document.getElementById('image'+id).src=img_open;
}
else // it's already showing
{
// hide the less link
document.getElementById('msglesslink'+id).style.display='none';
// show the more link
document.getElementById('msglink'+id).style.display='inline';
// hide the span
span.style.display = 'none';
// switch the image
document.getElementById('image'+id).src=img_closed;
}
}
posted by Kirklander to computers & internet (6 comments total) 2 users marked this as a favorite
You can run javascript directly by typing it on the URL bar. For example, to run toggleMessage on all IDs from 0 to 100, with the page up, just type this in the address bar and press enter:
javascript:for(id=0;id<>
posted by zsazsa at 3:27 PM on March 7


Dagnabbit. Trying again:
javascript:for(id=0;id<=100;id++){toggleMessage(id)}
posted by zsazsa at 3:29 PM on March 7


Thanks, that sounds amazing except I am trying it in Firefox and nothing is happening. Maybe my Firefox is messed up.
posted by Kirklander at 3:32 PM on March 7


Hmm, looks like I can type in toggleMessage(1), toggleMessage(2), etc. which is cool but i wonder if something is missing in the loop.
posted by Kirklander at 3:44 PM on March 7


Oh wow, thanks, this was wicked. It only worked when I changed it to

javascript:for(id=1;id<>
, goodness knows why. But thanks.
posted by Kirklander at 3:51 PM on March 7


By the way, you can also add that javascript code to a bookmark that you can run at any time. It then becomes a bookmarklet.
posted by zsazsa at 5:54 PM on March 7


« Older A question of etiquette: Can I...   |   how many Americans own 40 acre... Newer »

You are not logged in, either login or create an account to post comments