#!/usr/bin/perl # Author: Hai Binh Nguyen # Name: u2v.pl # Desc: This script grabs urls (sent on channels and pm's), stores them into # a list and load them up by their reference numbers # + "/zurl" will load the last url added to the list # + "/zurl [id] [id] ..." will load urls specified by their # + "/zurl list" will list the captured urls use strict; use vars qw ($VERSION %IRSSI); use Irssi; use Term::ANSIColor qw (:constants); $VERSION = "2004-04-12"; %IRSSI = ( authors => 'b1nhb00ng', contact => 'bb@vnlinux.org', name => 'zurl', description => 'multiple url grabber, handler', license => 'GPLv2', url => 'http://www.zecoj.com', ); my $last_url; my $recent = 1; my $MAX_URLS = 69; my @urls; sub find_url ($) { my ($text) = @_; if ($text =~ /((ftp:\/\/|http:\/\/|www)[a-zA-Z0-9\/\\\:\?\%\.\&\;=#\-\_\!\+\~@\$\(\)\,]+)/i) { return $1; } return undef; } sub event_private_message { my ($server, $text, $nick, $address) = @_; my $new_text = parse_msg ($server, $nick, $nick, $text); Irssi::signal_continue ($server, $new_text, $nick, $address); } sub event_public_message { my ($server, $text, $nick, $address, $target) = @_; my $new_text = parse_msg ($server, $target, $nick, $text); Irssi::signal_continue ($server, $new_text, $nick, $address, $target); } sub event_irc_action { my ($server, $text, $nick, $address, $target) = @_; my $new_text = parse_msg_action ($server, $target, $nick, $text); Irssi::signal_continue ($server, $new_text, $nick, $address, $target); } sub parse_msg ($$$$) { my ($server, $target, $nick, $line) = @_; my $url = find_url ($line); my $new; while ($url) { my ($first, $second) = split (/\Q$url/, $line, 2); # $recent = 1 if ($recent > $MAX_URLS); $urls[$recent-1] = { url => $url, }; $last_url = $url; my $hilight = RED." [$recent]".RESET; $url =~ s/\Q$url/CLEAR.GREEN.$url.$hilight/e; $recent++; # $new = $new.$first.$url; $line = $second; $url = find_url ($line); } $new = $new.$line; return $new; } sub parse_msg_action ($$$$) { my ($server, $target, $nick, $line) = @_; my $url = find_url ($line); my $new; while ($url) { my ($first, $second) = split (/\Q$url/, $line, 2); # $recent = 1 if ($recent > $MAX_URLS); $urls[$recent-1] = { url => $url, }; $last_url = $url; my $hilight = " [$recent]"; $url =~ s/\Q$url/$url.$hilight/e; $recent++; # $new = $new.$first.$url; $line = $second; $url = find_url ($line); } $new = $new.$line; return $new; } sub list_urls { if ($last_url) { my $i = 1; print CLIENTCRAP YELLOW."*** Captured URL's:".RESET; foreach (@urls) { my $url = $_->{url}; print CLIENTCRAP RED."[$i] ".RESET.$url; $i++; } } else { print CLIENTCRAP YELLOW."*** No URL's captured".RESET; } } sub call_browser ($) { my ($url) = @_; system ("galeon -n '$url'>/dev/null 2>&1 &"); #system ("z_firefox '$url'&"); } sub zurl_cmd { my ($arg, $server, $witem) = @_; my @args = split(/ /, $arg); if (scalar(@args) == 0) { if ($last_url) { call_browser($last_url); } } elsif ($args[0] eq 'list') { list_urls; } else { foreach (@args) { next unless /\d+/; next unless defined $urls[$_-1]; my $url = $urls[$_-1]->{url}; call_browser($url); } } } Irssi::signal_add_last("message private", "event_private_message"); Irssi::signal_add_last("message public", "event_public_message"); Irssi::signal_add_last("message irc action", "event_irc_action"); Irssi::command_bind ("zurl", "zurl_cmd");