There is a very old website I use and the data is not displayed in a friendly fashion. I would like to write a userscript (javascript/jQuery) that assists the readability of this site. The content looks like (the HTML comments are my own, to help show this):
<font size="3" face="Courier">
<br>
<!-- Begin entry 1 -->
Name1 (Location1) - Date1:
<br>
Text1
<br>
Text1 (continued)
<br>
Text1 (continued)
<br>
<br>
<!-- Begin entry 2 -->
Name2 (Location2) - Date2:
<br>
Text2
<br>
Text2 (continued)
<br>
<br>
Text2 (continued)
<br>
Text2 (continued)
<br>
<br>
<!-- Begin entry 3 -->
Name3 (Location3) - Date3:
<br>
Text3
<br>
Text3 (continued)
<br>
Text3 (continued)
<br>
<br>
<br>
Text3 (continued)
<br>
Text3 (continued)
<!-- Below is Text3, but a user copied Entry1 here -->
Name1 (Location1) - Date1: <!-- text3 -->
<br> <!-- text3 -->
Text1 <!-- text3 -->
<br> <!-- text3 -->
Text1 (continued) <!-- text3 -->
<br> <!-- text3 -->
Text1 (continued) <!-- text3 -->
<br>
<br>
<!-- Begin entry 4 -->
Name4 ...
......
</font>
- Example of names:
Bob Dole,SMITH,JOHN - Example of locations:
via Web,INTERNAL - Example of dates:
Jul 25, 2011 - 1317 EDT,Dec 30, 2011 - 1411 EST - Example of Text1/Text2/etc:
Blah blah * (test) text goes here -Thanks Here: there
As you can see, two <br> always come before the next “entry” (name, location, date) but since the text is free text it can also contain various <br> including 2 or more. Another issue is if the text also contains Name (Location) - Date pasted from say another entry elsewhere.
So if I wanted to write a script that could be added to Google Chrome where it say added a button that would collapse (or uncollapse if already collapsed) each entry, is that possible? The issue I’m having is that since there is no unique element starting or ending an entry, I’m not sure how to begin this.
The general concept is to loop through each “entry” (header being name/location/date) and the text that follows that up until the next header) and allow each “entry” to be collapsible (such as Reddit comments are collapsible).
Or for a more simple concept, what if I wanted to mark every other entry with red font? So then all of entry1 would be black font, entry2 would be red font, entry3 would be black font, entry4 would be red font, and so on.
For this kind of thing, parse the entries in a state-machine loop.
The following code was always the first answer to:
See a demo of it at jsFiddle.
UPDATE:
The question’s HTML did not match the actual page structure. Updated the script below to account for that, and also added the CSS to the script-code:
If nested/quoted entries are to be wrapped separately, you will also need to recurse. For nested/quoted entries, open a new question after this one is answered.
Note: The new sample HTML has multiple pairs of
<html>tags and 2 sets of entries! This is probably a cut-and-paste error, but if it is not, open a new question if help is needed for the easy mod to process multiple sets.