#!/bin/perl -w # Author.....: Valacar # Date.......: Oct 19th, 2006 # Description: Converts Stylish's resource file (stylish.rdf) into individual CSS files. # Usage......: Run the script in the same directory as stylish.rdf (located in # your Firefox profile directory). File output will be to the same # directory as the RDF file, so I suggest copying the RDF file to # a new directory and then running the script. use strict; use XML::Twig; my $twig = new XML::Twig(TwigHandlers => { 'RDF:Description' => \&myHandler } ); $twig->parsefile("stylish.rdf"); sub myHandler { my($twig, $element) = @_; # get function parameters # get description (style's title) attribute my $stylishDescription = $element->{'att'}->{'stylish:description'}; # get CSS code my $stylishCode = $element->first_child('stylish:code')->text; my $illegalFileChars = '\/:*?"<>|'; # illegal chars on win32 my $filename = $stylishDescription . '.css'; $filename =~ s/\w:/ -/g; $filename =~ s/[$illegalFileChars]/-/g; open(OUTFILE, ">$filename") or die "could not create file: $filename\n"; print OUTFILE $stylishCode; close OUTFILE; print "Processed: $stylishDescription\n"; $twig->purge; }