forked from samyk/samytools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpb2url
executable file
·59 lines (51 loc) · 1.15 KB
/
pb2url
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
#!/usr/bin/perl
#
# when dropbox screenshot goes into paste buffer,
# rewrite url to samy.pl and forward directly to raw image
# -samy kamkar
=cut
my samy.pl/s/.htaccess:
RewriteEngine on
RewriteRule ^(.*)/(.*)$ https://www.dropbox.com/s/$1/$2?raw=1 [L,NC]
=cut
if ($ARGV[0] ne "-F")
{
if (my $p = fork)
{
die "Running in bg! (pid $p)";
}
close(STDERR);
close(STDIN);
close(STDOUT);
}
my $SLEEP = 0.3;
my $URL = "https://samy.pl/";
use strict;
my $ourl;
while (1)
{
my $url = `/usr/bin/pbpaste`;
if ($ourl ne $url)
{
$ourl = $url;
# open F, ">>/Users/samy/pb.txt";
# print F "$url\n";
# close F;
}
if ($url =~ m|^https://www.dropbox.com/(sh?)/(.*?)/(.*?)\?dl=0$|)
{
my ($pre, $rand, $file) = ($1, $2, $3);
$file =~ s/Screenshot.*(\..*)/ss$1/;
my $nurl = $URL . "$pre/$rand/$file";
system("echo '$nurl' | pbcopy");
# print STDERR "Copied $nurl\n";
}
elsif ($url =~ m|^https://www.wikiwand.com/en/(.*)$|)
{
my $nurl = "https://en.wikipedia.org/wiki/$1";
system("echo '$nurl' | pbcopy");
}
#https://www.dropbox.com/s/gegnifzzcv1wepe/ds1.png?dl=0
# sleep
select(undef, undef, undef, $SLEEP);
}