http://www.perlmonks.org?node_id=765794


in reply to [Free Nodelet Hack] Highlight monk names accordingly their XP level

Since monks keep getting promoted, here is a script to regenerate the javascript from the current Saints in our Book:

use strict; use warnings; use LWP::UserAgent; use HTML::TreeBuilder; my $ua = LWP::UserAgent->new(); $ua->agent("MyApp/0.1"); my $req = HTTP::Request->new(GET => 'http://perlmonks.org/?node=Saints +%20in%20our%20Book'); my $res = $ua->request($req); unless($res->is_success) { die $res->status_line; } my $tree = HTML::TreeBuilder->new(); $tree->parse($res->content); $tree->eof(); print <<'EOF' ; <style type="text/css"> .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 !importan +t; } </style> <script type="text/javascript"> <!-- // "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 <<'EOF' ; function Colorize() { var links = document.links; for( var i=links.length-1; i>=0 ; --i ) if ( /\?node_id=(\d+)$/.test(links[i].href) && SaintsBook[RegE +xp.$1] ) links[i].className = SaintsBook[RegExp.$1]; } setTimeout('Colorize()', 600); // --> </script> EOF sub dump_saints { my $element = shift; if($element->tag() eq 'table') { my @contents = $element->content_list; if(@contents > 10) { # The saints table has lots of rows my %saints; shift(@contents); # The first row is headers foreach my $row (@contents) { my ($id) = (((($row->content_list())[1]->content_list( +))[0]->content_list())[0]->attr('href') =~ m/=(.*)/); my ($level) = ((($row->content_list())[3]->content_lis +t())[0] =~ m/([^ ]*)/); push(@{$saints{$level}}, $id); } foreach my $level (keys %saints) { print "var $level = [" . join(',',@{$saints{$level}}) +. "];\nfor( var i=$level.length-1; i>=0; i--) SaintsBook[$level\[i]] += '$level';\n\n"; } } } foreach my $e ($element->content_list()) { if(ref($e) and $e->isa('HTML::Element')) { dump_saints($e); } } }