From: nauski Date: Fri, 29 Dec 2023 14:50:32 +0000 (+0200) Subject: added speedread.pl X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=f9afd6897bfcbdb1fe8cc92804ff8e9f64a4d801;p=irssi-scripts.irssi.org.git added speedread.pl --- diff --git a/scripts/speedread.pl b/scripts/speedread.pl new file mode 100644 index 0000000..b9f5c23 --- /dev/null +++ b/scripts/speedread.pl @@ -0,0 +1,47 @@ +use strict; +use warnings; +use Irssi; + +our $VERSION = '1.0'; +our %IRSSI = ( + authors => 'Juha Kesti', + contact => 'nauski@nauski.com', + name => 'speedread.pl', + description => 'Bolds the first (1-3) characters of each word.', + license => 'Public Domain', +); + +sub bold_first_three { + my $msg = shift; + my @words = split(/\s+/, $msg); + my @processed_words; + + for my $word (@words) { + if (length($word) > 3) { + $word = "\x02" . substr($word, 0, 3) . "\x02" . substr($word, 3); + } else { + $word = "\x02" . substr($word, 0, 1) . "\x02" . substr($word, 1); + } + push @processed_words, $word; + } + + return join(' ', @processed_words); +} +sub outgoing_msg_handler { + my ($msg, $server, $witem) = @_; + if (defined $witem && ($witem->{type} eq "CHANNEL" || $witem->{type} eq "QUERY")) { + my $new_msg = bold_first_three($msg); + $witem->command("msg -channel " . $witem->{name} . " $new_msg"); + Irssi::signal_stop(); + } +} + +sub incoming_msg_handler { + my ($server, $msg, $nick, $address, $target) = @_; + my $new_msg = bold_first_three($msg); + Irssi::signal_continue($server, $new_msg, $nick, $address, $target); +} + +Irssi::signal_add('send text', 'outgoing_msg_handler'); +Irssi::signal_add('message public', 'incoming_msg_handler'); +