;Image Viewer Script
;Made by nick1
;Last edit March 17 2013
When someone puts an image link in the chat it will open it an mIRC window instead of a browser tab.
Directions: Copy entire code into new remote file. Click on a link to an image and it will open up in a window instead of a browser tab.
Feedback (i.e. comments, questions, concerns, suggestions, jokes, etc.) greatly appreciated.
;Image Viewer Script
;Made by nick1
;Last edit March 17 2013
on $^*:hotlink:/((?:(?:(?:https?)\72\/\/)|(?:www)\.)\S+)(?:(?:jpg|gif|jpeg|png)|(?<=puu\.sh\/)|(?<=my\.jetscreenshot\.com\/)|(?<=imgur\.com\/)(?:\w+))/Sig:*:{
if ($hotlink(event) == sclick) && (!$sock(getpic)) {
set %getpic $remove($1,http://,https://)
;special link replacement (below) will only work if filetype is JPG
if ((*puu.sh* iswm %getpic) && (*.* !iswm $remove(%getpic,u.sh))) {
set %getpic %getpic $+ .jpg
}
if ((*imgur.com* iswm %getpic) && (*.* !iswm $remove(%getpic,r.co))) {
set %getpic $replace($remove(%getpic,/gallery),imgur.com,i.imgur.com) $+ .jpg
}
if ((*my.jetscreenshot.com/* iswm %getpic) && (*.* !iswm $remove(%getpic,t.co,y.je))) {
set %getpic %getpic $+ .jpg
}
if (!$file($qt($getdir $+ $gettok(%getpic,-1,47)))) {
sockopen GetPic $gettok(%getpic,1,47) 80
}
}
}
On *:sockopen:getpic:{
sockwrite -nt $sockname GET $+(/,$gettok(%getpic,2-,47)) HTTP/1.1
sockwrite -nt $sockname Host: $sock(getpic).addr
sockwrite -nt $sockname
}
on *:sockread:getpic:{
if ($sockerr) return
if (!$sock($sockname).mark) {
var %SockReader
sockread %SockReader
if (%SockReader == $null) {
sockmark $sockname 1
.timerclose $+ $sockname -m 1 3300 imagetimeout
}
}
else {
sockread -f &picture
.bwrite $qt($getdir $+ $gettok(%getpic,-1,47)) -1 -1 &picture
}
}
alias imagetimeout {
sockclose getpic
showpic
}
on *:sockclose:getpic: {
.timerclose $+ $sockname off
showpic
}
Alias ShowPic {
var %file $qt($getdir $+ $gettok(%getpic,-1,47))
var %w $pic(%file).width
var %h $pic(%file).height
if (%w == 0) {
.remove %file
halt
}
else {
var %win $+(@,$gettok(%getpic,-1,47),-,$chr(40),%w,x,%h,$chr(41))
window -dCpk0 %win -1 -1 $calc(%w + 17) $calc(%h + 34)
.timer $+ $gettok(%file,$numtok(%file,32),32) 1 120 .remove %file
drawpic %win -1 -1 %file
}
unset %getpic
}
Oh nice :p
I had something really similar. But if IIRC ON Hotlink was updated and I haven't modified the script yet, so it doesn't work anymore :
Yeah here it is :P : http://www.hawkee.com/snippet/8903/
A few things I've spotted real quick
1: why is the 7 escaped in your regex @ gopher)\72
2: HTTPS, FTP and gopher, afaik, is a competely different protocol from http, meaning the GET ... Host: headers are invalidly used.
3: Instead of coding the 'redirect' for puu.sh, why not just have your sockets follow redirects?
Thanks for the feedback @SReject
1 and 2 - I'm not sure because I didn't make the regex string. (thanks to Wiz126 #msl swiftirc for it) - I will look into changing it to better fit this script in the future. (Also I don't really see people link to FTP or Gopher images so they seem useless haha)
I made some edits to the code above.
I didn't really test it, but i think this would be a far better regex:
/(?:http:\/\/)?(?:www\.)?(|(\S+\.(?:jpe?g|gif|png))|(puu\.sh\/\w+))/Sig
@Conscious after I commented, I remember
@SReject It works for https links. What are you doing? I also thinkit would work for FTP links. I don't know shit about gopher.
Appreciate it though. Can you add imgur in there? (I'm shit with regex).
@illhawkthat It doesn't work for https or ftp links. It is basically converting the URL to a HTTP link. Some/Most servers support an HTTP fall back for HTTPS links.
Sorry if I keep coming off sounding arrogant, it's not my intention. If you wanted true HTTPS(not sure, but I think FTP aswell) support, you could use one of these inplace of your sockets:
Call back style downloading of a file:
http://www.hawkee.com/snippet/9318/
Semi-blocking downloading of a file:
http://www.hawkee.com/snippet/8993/
Thanks @Conscious I'll put up a new regex string within the week when I can find someone to make one for me haha. I appreciate all the feedback!
Glad it's helpful!