new-words

diff misc/word-changer.pl @ 66:53ba2847501f

added misc scripts
author Igor Chubin <igor@chub.in>
date Tue Mar 27 14:16:46 2012 +0200 (2012-03-27)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/misc/word-changer.pl	Tue Mar 27 14:16:46 2012 +0200
     1.3 @@ -0,0 +1,87 @@
     1.4 +our $change_matrix = '
     1.5 +um über mit von vom nach zum zur in an auf
     1.6 +der das des dem den ein einer einem einen eines
     1.7 +';
     1.8 +
     1.9 +@colors = qw(ccccff 7aedaa ddeecc ffccee);
    1.10 +
    1.11 +our %change_matrix;
    1.12 +our %color;
    1.13 +our $dropdown_number = 0;
    1.14 +
    1.15 +$i = 0;
    1.16 +for (split /\n/, $change_matrix){
    1.17 +    next if /^\s*$/;
    1.18 +    my @words = sort(split /\s+/);
    1.19 +    for my $kw (@words) {
    1.20 +        $change_matrix{$kw} = [ "???", @words ];
    1.21 +        $color{$kw} = $colors[$i%@colors];
    1.22 +    }
    1.23 +    # uppercase
    1.24 +    for (@words) {
    1.25 +        s/(.)(.*)/\U$1\E$2/;
    1.26 +    }
    1.27 +    for my $kw (@words) {
    1.28 +        $change_matrix{$kw} = [ "???", @words ];
    1.29 +        $color{$kw} = $colors[$i%@colors];
    1.30 +    }
    1.31 +    $i += 1;
    1.32 +};
    1.33 +
    1.34 +for (keys(%change_matrix)) {
    1.35 +    print "$_ => ".join(", ", @{$change_matrix{$_}})."\n";
    1.36 +    print "$_ => ".$color{$_}."\n";
    1.37 +}
    1.38 +
    1.39 +sub generate_drop_down($)
    1.40 +{
    1.41 +    my $name = "dropdown$dropdown_number";
    1.42 +    $dropdown_number += 1;
    1.43 +    my $word = $_[0];
    1.44 +    my @variants = @{$change_matrix{$word}};
    1.45 +    $options = join("", map {"<option value=$_>$_</option>"} @variants);
    1.46 +    my $color = $color{$word};
    1.47 +    if ($color) {
    1.48 +        $color = "background:#$color";
    1.49 +    }
    1.50 +    my $onchange = "onchange='javascript:myAlert(this.form.$name, \"$word\")'";
    1.51 +    return "<form style='display:inline!important;'><select name='$name' $onchange style='font-size:80%; $color'>".$options."</select></form>"; 
    1.52 +}
    1.53 +sub highlight_word($$)
    1.54 +{
    1.55 +    my $tag = $_[0];
    1.56 +    my $text = $_[1];
    1.57 +    if ($tag=~/^<[aA]/) {
    1.58 +        return $tag.$text;
    1.59 +    }
    1.60 +    my $re = join("|", keys(%change_matrix));
    1.61 +    #$text =~ s@ ([Aa]uf) @<input contenteditable=True style='text-color:#eecccc' />@g;
    1.62 +    $text =~ s@(^|[;> ])($re)(?=([ <]|$))@"$1".generate_drop_down($2)@eg;
    1.63 +    return $tag.$text;
    1.64 +}
    1.65 +
    1.66 +$jquery = "<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'></script>";
    1.67 +local $/;
    1.68 +$text = <>;
    1.69 +$text =~ s@(<a.*?>)(.*?)(</a>)@$2@g;
    1.70 +$text =~ s/(<.*?>)([^<]*)(?=<)/highlight_word($1, $2)/eg;
    1.71 +$info_div = "
    1.72 +    <div style='
    1.73 +        position:fixed;
    1.74 +        bottom:0;
    1.75 +        right:0;
    1.76 +        color:white;
    1.77 +        background-color:green;
    1.78 +        font-size:70%;
    1.79 +        padding:5pt;
    1.80 +        z-index:1000;
    1.81 +        border-top-left-radius:
    1.82 +        5pt;-moz-border-radius-topleft:5pt;
    1.83 +        '>
    1.84 +            <span id='wrong_answers' style='color:#ff2222;'>0</span>&nbsp;&nbsp;
    1.85 +            <span id='correct_answers'>0</span>&nbsp;&nbsp;
    1.86 +            <span id='yet_to_answer'>$dropdown_number</span>
    1.87 +    </div>";
    1.88 +
    1.89 +$text =~ s@(<body[^>]*>)@<script type="text/javascript" src="Kiew.js"></script>$jquery$1$info_div@i;
    1.90 +print $text;