new-words

view misc/word-changer.pl @ 67:87bb1c5e6616

added de script to misc/
author Igor Chubin <igor@chub.in>
date Wed Mar 28 15:54:30 2012 +0200 (2012-03-28)
parents
children
line source
1 our $change_matrix = '
2 um über mit von vom nach zum zur in an auf
3 der das des dem den ein einer einem einen eines
4 ';
6 @colors = qw(ccccff 7aedaa ddeecc ffccee);
8 our %change_matrix;
9 our %color;
10 our $dropdown_number = 0;
12 $i = 0;
13 for (split /\n/, $change_matrix){
14 next if /^\s*$/;
15 my @words = sort(split /\s+/);
16 for my $kw (@words) {
17 $change_matrix{$kw} = [ "???", @words ];
18 $color{$kw} = $colors[$i%@colors];
19 }
20 # uppercase
21 for (@words) {
22 s/(.)(.*)/\U$1\E$2/;
23 }
24 for my $kw (@words) {
25 $change_matrix{$kw} = [ "???", @words ];
26 $color{$kw} = $colors[$i%@colors];
27 }
28 $i += 1;
29 };
31 for (keys(%change_matrix)) {
32 print "$_ => ".join(", ", @{$change_matrix{$_}})."\n";
33 print "$_ => ".$color{$_}."\n";
34 }
36 sub generate_drop_down($)
37 {
38 my $name = "dropdown$dropdown_number";
39 $dropdown_number += 1;
40 my $word = $_[0];
41 my @variants = @{$change_matrix{$word}};
42 $options = join("", map {"<option value=$_>$_</option>"} @variants);
43 my $color = $color{$word};
44 if ($color) {
45 $color = "background:#$color";
46 }
47 my $onchange = "onchange='javascript:myAlert(this.form.$name, \"$word\")'";
48 return "<form style='display:inline!important;'><select name='$name' $onchange style='font-size:80%; $color'>".$options."</select></form>";
49 }
50 sub highlight_word($$)
51 {
52 my $tag = $_[0];
53 my $text = $_[1];
54 if ($tag=~/^<[aA]/) {
55 return $tag.$text;
56 }
57 my $re = join("|", keys(%change_matrix));
58 #$text =~ s@ ([Aa]uf) @<input contenteditable=True style='text-color:#eecccc' />@g;
59 $text =~ s@(^|[;> ])($re)(?=([ <]|$))@"$1".generate_drop_down($2)@eg;
60 return $tag.$text;
61 }
63 $jquery = "<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'></script>";
64 local $/;
65 $text = <>;
66 $text =~ s@(<a.*?>)(.*?)(</a>)@$2@g;
67 $text =~ s/(<.*?>)([^<]*)(?=<)/highlight_word($1, $2)/eg;
68 $info_div = "
69 <div style='
70 position:fixed;
71 bottom:0;
72 right:0;
73 color:white;
74 background-color:green;
75 font-size:70%;
76 padding:5pt;
77 z-index:1000;
78 border-top-left-radius:
79 5pt;-moz-border-radius-topleft:5pt;
80 '>
81 <span id='wrong_answers' style='color:#ff2222;'>0</span>&nbsp;&nbsp;
82 <span id='correct_answers'>0</span>&nbsp;&nbsp;
83 <span id='yet_to_answer'>$dropdown_number</span>
84 </div>";
86 $text =~ s@(<body[^>]*>)@<script type="text/javascript" src="Kiew.js"></script>$jquery$1$info_div@i;
87 print $text;