]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
added speedread.pl
authornauski <redacted>
Fri, 29 Dec 2023 14:50:32 +0000 (16:50 +0200)
committernauski <redacted>
Fri, 29 Dec 2023 14:50:32 +0000 (16:50 +0200)
scripts/speedread.pl [new file with mode: 0644]

diff --git a/scripts/speedread.pl b/scripts/speedread.pl
new file mode 100644 (file)
index 0000000..b9f5c23
--- /dev/null
@@ -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');
+
git clone https://git.99rst.org/PROJECT