aboutsummaryrefslogtreecommitdiff
path: root/urlcleaner.pl
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-12-26 17:08:34 -0500
committerB. Watson <urchlay@slackware.uk>2024-12-26 17:08:34 -0500
commit9eed830f296dab257759f5276d0963467007aa6b (patch)
tree83d6225d248ec8d4026b514d8b9b248e6c0fce32 /urlcleaner.pl
downloadstupid-irssi-tricks-9eed830f296dab257759f5276d0963467007aa6b.tar.gz
initial commit
Diffstat (limited to 'urlcleaner.pl')
-rw-r--r--urlcleaner.pl103
1 files changed, 103 insertions, 0 deletions
diff --git a/urlcleaner.pl b/urlcleaner.pl
new file mode 100644
index 0000000..a1dc0f6
--- /dev/null
+++ b/urlcleaner.pl
@@ -0,0 +1,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");