1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#!/usr/bin/perl
# Avoid spamming your friends with *huge* URLs from ebay and amazon.
# The extra junk at the end of the URL is session and tracking
# info. It's probably not a security problem to let people see it, but
# it does hurt their eyes.
# What this script does is:
# 1. Modify any message from you (after you hit Enter and before it
# goes to the IRC server) and remove all the CGI params from URLs
# matching https://www.ebay.com or https://www.amazon.com.
# 2. Modify any amazon/ebay URLs in incoming public or private message,
# the same way, before they're printed in your irssi window. You
# will see only the trimmed version.
# If you *really* want to paste the full URLs, you still can: just
# prefix your line with -- (the -- goes at the front of your input,
# not directly in front of the URL).
# If you *really* want to see the original URL, use the /untrim
# command. It'll show the previous (up to) 3 URLs in their original
# forms. The list is cleared after printing.
# Sample URLs:
# https://www.amazon.com/Fender-Original-Instrument-Straight-Straight-18-6-Foot/dp/B07YSRML8M?pd_rd_w=APcow&content-id=amzn1.sym.55c0153f-1fb7-42ff-8241-d1c0f3732289&pf_rd_p=55c0153f-1fb7-42ff-8241-d1c0f3732289&pf_rd_r=QM0V2R6T6MXQAH39WATH&pd_rd_wg=Fsarl&pd_rd_r=58846f08-1923-4e41-9191-9cf3dc7bf8ae&ref_=sspa_dk_detail_img_1&sp_csd=d2lkZ2V0TmFtZT1zcF9kZXRhaWxfdGhlbWF0aWM&th=1
# https://www.ebay.com/itm/225034857497?_skw=2%22+round+iron-on+patch&itmmeta=01JDKKYWPHG9RB0ENME87YF4WX&hash=item34651f6c19:g:JdYAAOSwTPhirSFD&itmprp=enc%3AAQAJAAAA8HoV3kP08IDx%2BKZ9MfhVJKkDq1GsENxQhDILz02EizByT9tnvQUmV4MujHHWVdHvzDDR1hGWeP2UUa7RpgCE6e1iSZDTiRBaKCuEHmRQKKOHf3tkFUKhVfo0M2r86ABaDgxmu9zvRrZsee0ZR2J41YUwcrmOBwtor3hFjzLto7UWULyUuydtBHTwrzWaegH0YIzpRqiv3fJx6mgopXNBME%2FuTIK2B%2ByyoyC07G6ZMYuCjsxXcwMUVB9qxuRjD6t3%2BiW%2B1bKLkkcB
# For both amazon and ebay, none of the CGI params are needed. Just chop
# off everything from ? on.
# TODO: clean up youtube URLs. Not sure what all the CGI params are, or which
# are redundant/unwanted. Domains:
# youtube.com
# m.youtube.com
# youtu.be
# youtube.googleapis.com
# youtubei.googleapis.com
# Some others are listed here:
# https://support.google.com/a/answer/6214622?hl=en
# ...but we only care about ones that support $domain/watch?v=...
use Irssi qw/
signal_add_first
signal_continue
signal_register
command_bind
/;
our $VERSION = "0.1";
our %IRSSI = (
authors => 'Urchlay',
contact => 'Urchlay on Libera',
name => 'urlcleaner',
description => 'trim down ebay and amazon URLs',
license => 'WTFPL',
url => 'none',
);
our @orig_urls = ();
sub push_url {
return if grep { $_ eq $_[0] } @orig_urls; # skip dups
push @orig_urls, $_[0];
shift @orig_urls if @orig_urls > 3;
}
sub trim_url {
my $old = $_[0];
$_[0] =~ s{((https://www.(?:ebay|amazon).com\S+)\?\S*)}{$2};
push_url($1) if $old ne $_[0];
return $_[0];
}
sub on_send_text {
if($_[0] !~ /^\s*--/) {
$_[0] = trim_url($_[0]);
}
signal_continue(@_);
}
sub on_public_msg {
$_[1] = trim_url($_[1]);
signal_continue(@_);
}
sub cmd_untrim {
print "No trimmed URLs" unless @orig_urls;
print "Original URL:\n$_" for @orig_urls;
@orig_urls = ();
}
# I'm not 100% sure this signal_register is correct. It seems like I should be
# specifying more arguments (since on_send_text() actually gets 3 args). It
# does, however, work on at least irssi-1.4.4.
signal_register({ "send text", [ "string" ] });
signal_add_first("send text", "on_send_text");
signal_add_first("message public", "on_public_msg");
signal_add_first("message private", "on_public_msg");
command_bind("untrim", "cmd_untrim");
|