<?xml version="1.0" encoding="windows-1252"?>
<node id="765794" title="Re: [Free Nodelet Hack] Highlight monk names accordingly their XP level" created="2009-05-23 00:17:09" updated="2009-05-23 00:17:09">
<type id="11">
note</type>
<author id="675798">
ig</author>
<data>
<field name="doctext">
&lt;p&gt;Since monks keep getting promoted, here is a script to regenerate the javascript from the current [Saints in our Book]:&lt;/p&gt;

&lt;readmore&gt;
&lt;c&gt;
use strict;
use warnings;

use LWP::UserAgent;
use HTML::TreeBuilder;


my $ua = LWP::UserAgent-&gt;new();

$ua-&gt;agent("MyApp/0.1");

my $req = HTTP::Request-&gt;new(GET =&gt; 'http://perlmonks.org/?node=Saints%20in%20our%20Book');

my $res = $ua-&gt;request($req);
unless($res-&gt;is_success) {
    die $res-&gt;status_line;
}


my $tree = HTML::TreeBuilder-&gt;new();
$tree-&gt;parse($res-&gt;content);
$tree-&gt;eof();

print &lt;&lt;'EOF' ;
&lt;style type="text/css"&gt;
.Pope         { font-weight: bold; color: #FF3010 !important; }
.Apostle      { font-weight: bold; color: #F84020 !important; }
.Saint        { font-weight: bold; color: #F44030 !important; }
.Sage         { font-weight: bold; color: #F04040 !important; }
.Cardinal     { font-weight: bold; color: #E04050 !important; }
.Archbishop   { font-weight: bold; color: #D04060 !important; }
.Bishop       { font-weight: bold; color: #C03070 !important; }
.Chancellor   { font-weight: bold; color: #B03080 !important; } 
.Canon        { font-weight: bold; color: #A03090 !important; }
.Abbot        { font-weight: bold; color: #9030A0 !important; }
.Monsignor    { font-weight: bold; color: #8020B0 !important; } 
.Prior        { font-weight: bold; color: #7020C0 !important; }
.Parson       { font-weight: bold; color: #6020D0 !important; }
.Vicar        { font-weight: bold; color: #5020E0 !important; } 
.Priest       { font-weight: bold; color: #4010F0 !important; }
.Curate       { font-weight: bold; color: #3010FF !important; }
.HighPriority { font-weight: bold; background-color: #FFFF00 !important; } 
&lt;/style&gt;



&lt;script type="text/javascript"&gt;
&lt;!--
//  "When a society has no colored pants to differentiate class...
//  ...it's a society without purpose"  --  Wef
//  http://en.wikipedia.org/wiki/Kin-dza-dza!

var SaintsBook = new Object();

EOF

dump_saints($tree);

print &lt;&lt;'EOF' ;
function Colorize() {
    var links = document.links;
    for( var i=links.length-1; i&gt;=0 ; --i )
        if ( /\?node_id=(\d+)$/.test(links[i].href) &amp;&amp; SaintsBook[RegExp.$1] )
            links[i].className = SaintsBook[RegExp.$1];
}

setTimeout('Colorize()', 600);

// --&gt;
&lt;/script&gt;
EOF




sub dump_saints {
    my $element = shift;

    if($element-&gt;tag() eq 'table') {
        my @contents = $element-&gt;content_list;
        if(@contents &gt; 10) {    # The saints table has lots of rows
            my %saints;
            shift(@contents);   # The first row is headers
            foreach my $row (@contents) {
                my ($id) = (((($row-&gt;content_list())[1]-&gt;content_list())[0]-&gt;content_list())[0]-&gt;attr('href') =~ m/=(.*)/);
                my ($level) = ((($row-&gt;content_list())[3]-&gt;content_list())[0] =~ m/([^ ]*)/); 
                push(@{$saints{$level}}, $id);
            }
            foreach my $level (keys %saints) {
                print "var $level = [" . join(',',@{$saints{$level}}) . "];\nfor( var i=$level.length-1; i&gt;=0; i--) SaintsBook[$level\[i]] = '$level';\n\n";
            }
        }
    }

    foreach my $e ($element-&gt;content_list()) {
        if(ref($e) and $e-&gt;isa('HTML::Element')) {
            dump_saints($e);
        }
    }
}
&lt;/c&gt;
&lt;/readmore&gt;</field>
<field name="root_node">
752253</field>
<field name="parent_node">
752253</field>
</data>
</node>
