Difference between revisions of "URL-logger"
From Scriptwiki
m (a little update) |
m (Fixing delete from DB. no biggies.) |
||
(20 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | Screenshots:<br /> | |
− | [[:Image:ss_url_color.jpg|Screenshot 1: Colored links]]<br /> | + | [[:Image:ss_url_color.jpg|Screenshot 1: Colored links]]<br /> |
− | [[:Image:ss_url_search.jpg|Screenshot 2: Links search]] | + | [[:Image:ss_url_search.jpg|Screenshot 2: Links search]] |
− | + | ||
− | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | + | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
; | ; | ||
; URL-logger with colored and underlined links by Cail at Quakenet -> #help.script | ; URL-logger with colored and underlined links by Cail at Quakenet -> #help.script | ||
Line 10: | Line 10: | ||
; Tested and works on mIRC 6.2 and above (i recommend using >6.21 for $regsubex to work correctly) | ; Tested and works on mIRC 6.2 and above (i recommend using >6.21 for $regsubex to work correctly) | ||
; | ; | ||
− | ; This script uses spopup.dll ( | + | ; This script uses spopup.dll (OPTIONAL! you only need this if you want a new popup with info and some new features.), |
; to replace mirc's builtin url-popup | ; to replace mirc's builtin url-popup | ||
− | ; spopup.dll is made by | + | ; spopup.dll is made by Saturn, and you can get it from http://www.xise.nl/mirc/ |
− | ; | + | ; NOTE! Depending on how your mIRC is set up, your working path might be mirc's root dir, or Users/AppData folder |
+ | ; For example in Windows 7 the AppData folder would be: C:\Users\HappyUser\AppData\Roaming\mIRC | ||
+ | ; Note this when placing the .dll somewhere and not giving full path in the script. | ||
+ | ; | ||
; Formats recognized links like: | ; Formats recognized links like: | ||
− | ; - <nowiki>"http://google.com" -> http://google.com</nowiki> | + | ; - <nowiki>"http://google.com"</nowiki> -> <nowiki>http://google.com</nowiki> |
− | ; - <nowiki> | + | ; - url('<nowiki>www.google.com</nowiki>'); -> <nowiki>www.google.com</nowiki> |
− | ; - <nowiki> | + | ; - (<nowiki>www.google.com/ahihi(kiaa)</nowiki>) -> <nowiki>www.google.com/ahihi(kiaa)</nowiki> |
; | ; | ||
; And some more cleanups, and adds '<nowiki>http://</nowiki>' in front of '<nowiki>www.</nowiki>' for storing. | ; And some more cleanups, and adds '<nowiki>http://</nowiki>' in front of '<nowiki>www.</nowiki>' for storing. | ||
Line 27: | Line 30: | ||
; 3) old link - is found from the file, but you haven't opened it | ; 3) old link - is found from the file, but you haven't opened it | ||
; | ; | ||
+ | ; Fetches title of youtube video's: | ||
+ | ; - Gets title of the video and stores it into the links.db (for searching) | ||
+ | ; - Echo's the title under the link in chat | ||
+ | ; - Hold down ctrl key when pressing enter if you post a link, to /msg the title into the channel | ||
+ | ; - Fill %sendYTtitleChans with channels separated by spaces (eg. %sendYTtitleChans #chan1 #chan2) to automatically | ||
+ | ; send the title into the channel when ever a youtube link is posted. | ||
; | ; | ||
; Thanks to: | ; Thanks to: | ||
− | ; - | + | ; - Saturn for the spopup.dll |
− | ; - | + | ; - Msmo for the cleanup regex |
− | |||
; | ; | ||
+ | ; | ||
+ | ; UPDATE 06/07/2014: Performance update! | ||
+ | ; - Added hashtables to be used on regular checks, speeding up the normal link flow, no more slowdowns with hundreds of thousands of links | ||
+ | ; - Changed youtube title fetcher to use youtube API for faster download & faster parsing | ||
+ | ; - Some bug fixes and general performance improvements | ||
+ | ; UPDATE 14/06/2013: Added support for fetching and storing title from youtube links | ||
+ | ; - fetches youtube video's title, stores it into the logfile, echoes the title on the channel | ||
+ | ; - hold down ctrl key when pressing enter, when you post a link, to send the title as /msg to the channel (overrides %sendYTtitleChans variable) | ||
+ | ; - set %sendYTtitleChans variable for channels you want to /msg the title automatically when a link is posted | ||
+ | ; (for example: %sendYTtitleChans #channel1 #channel2 #channel3) would send the title into the channel on those 3 channels | ||
+ | ; UPDATE 17/06/2007: Updated regex (fixed '<nowiki>www.someurl.com/something's_here</nowiki>' to show correctly), added a timer with 200ms delay | ||
+ | ; into the on keyup event (to prevent filtering while writing fast). | ||
+ | ; UPDATE 23/03/2007: Changed on keydown -> on keyup, much more efficient now, won't need so much checks, and allows you to | ||
+ | ; insert text infront/into the middle of the line. | ||
+ | ; UPDATE 29/01/2007: added a regex into on keydown event to halt the script if something else than \S was pressed | ||
+ | ; (now holding down shift/alt/ctrl doesn't affect it), and optimized the on keydown event a bit. | ||
; UPDATE 18/01/2007: added on input event for the search (optional), rearranged the dll-stuff into same place, | ; UPDATE 18/01/2007: added on input event for the search (optional), rearranged the dll-stuff into same place, | ||
− | ; fixed a bug that didn't color some opened links without | + | ; fixed a bug that didn't color some opened links without http:// (only www.) |
; fixed if (!$exists($spopupdll)) { return } from linkpopup to 'halt' (now shows the original popup) | ; fixed if (!$exists($spopupdll)) { return } from linkpopup to 'halt' (now shows the original popup) | ||
; added a $db alias to return the filename, users can choose their own path/filename for the file. | ; added a $db alias to return the filename, users can choose their own path/filename for the file. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
; | ; | ||
− | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | + | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
; $db returns the name of the database file, change this to whatever you want | ; $db returns the name of the database file, change this to whatever you want | ||
− | alias -l db { return $qt(links.db) } | + | alias -l db { return $qt($deltok($mircexe,-1,92) $+ \ $+ links.db) } |
+ | |||
+ | ; on start event for creating and loading the hash table | ||
+ | on *:start:{ | ||
+ | linkhash_load | ||
+ | } | ||
+ | |||
+ | alias linkhash_load { | ||
+ | ; free the old hashtable if it exists, and hmake a new one | ||
+ | if ($hget(links.hash)) { hfree links.hash } | ||
+ | hmake links.hash 1000 | ||
+ | |||
+ | ; filter links from DB file to the hashtable | ||
+ | filter -fk $db LinkHash_copy * | ||
+ | } | ||
+ | |||
+ | alias linkhash_copy { | ||
+ | tokenize 32 $1 | ||
+ | hadd links.hash $strip($3) $1- | ||
+ | } | ||
; alias to open the links window, and filter all of the urls into it | ; alias to open the links window, and filter all of the urls into it | ||
Line 60: | Line 97: | ||
; else the window is already open, so activate it | ; else the window is already open, so activate it | ||
else { window -a @links } | else { window -a @links } | ||
− | } | + | } |
; alias to return colorcodes for the script, change these values to whatever you like. | ; alias to return colorcodes for the script, change these values to whatever you like. | ||
Line 81: | Line 118: | ||
; if the line even has links, useless to loop through it if there are no links | ; if the line even has links, useless to loop through it if there are no links | ||
− | if | + | if ($regex(%string,/(?:\b(?:www.?\.|https?:\/\/|s?ftp:\/\/).)/i)) { |
; so the line has links, loop through tokens then | ; so the line has links, loop through tokens then | ||
− | var %x = $numtok(%string,32) | + | var %x = 1 |
− | + | while (%x <= $numtok(%string,32)) { | |
; we'll assign the current token into a variable %tok, for easier use later | ; we'll assign the current token into a variable %tok, for easier use later | ||
Line 91: | Line 128: | ||
; (it'll be checked if it's a 'valid' url, and useless stuff be removed around it, if it's not an url the alias will return $null | ; (it'll be checked if it's a 'valid' url, and useless stuff be removed around it, if it's not an url the alias will return $null | ||
var %tok = $gettok(%string,%x,32) | var %tok = $gettok(%string,%x,32) | ||
− | var %url = $url_parse(%tok) | + | var %url = $url_parse(%tok) |
; check if there is an url in variable %url | ; check if there is an url in variable %url | ||
− | if (%url) { | + | if (%url) { |
− | ; $url_log will take care of storing the url into a database file, and return appropriate color to use in coloring the link | + | ; $url_log will take care of storing the url into a database file, and return appropriate color (in $1) to use in coloring the link |
+ | ; also returns the linenumber of newly added link (in $2) if we want to store the title for it | ||
+ | ; and if we already have the title in the log, return that too in %titleLine | ||
var %indb = $url_log(%url) | var %indb = $url_log(%url) | ||
+ | var %linkColor = $gettok(%indb,1,32) | ||
+ | var %titleLine = $gettok(%indb,2-,32) | ||
; now we color and underline the url and assign it into %newurl, (%indb will be holding the color code number) | ; now we color and underline the url and assign it into %newurl, (%indb will be holding the color code number) | ||
− | ; then we replace the url part of the token, so that from | + | ; then we replace the url part of the token, so that from "url('www.something.com');" only the "www.something.com" part will be colored and underlined |
− | var %newurl = $+($clr(% | + | var %newurl = $+($clr(%linkColor),$chr(31),%url,$chr(31),$clr) |
− | var %newurl = $replace(%tok,%url,%newurl) | + | var %newurl = $replace(%tok,%url,%newurl) |
; and finally, we put the modified token back to the original string | ; and finally, we put the modified token back to the original string | ||
%string = $puttok(%string,%newurl,%x,32) | %string = $puttok(%string,%newurl,%x,32) | ||
+ | |||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; OPTIONAL: GET YOUTUBE TITLE | ||
+ | ; this part is for checking if it's a youtube link, and initiates the fetching of the video's title | ||
+ | ; this can be commented out or removed if you don't want this functionality | ||
+ | if (*youtube* iswm %url) || (*youtu.be* iswm %url) { | ||
+ | getTitle youtube %url $iif($chan,$chan,$iif($target != $me,$target,$nick)) %titleLine | ||
+ | } | ||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END OF OPTIONAL | ||
} | } | ||
− | + | inc %x | |
} | } | ||
} | } | ||
Line 116: | Line 165: | ||
; alias to trim the given url, returns $null if input isn't an url | ; alias to trim the given url, returns $null if input isn't an url | ||
− | ; big thanks to | + | ; big thanks to Msmo on Quakenet for this regex |
alias -l url_parse { | alias -l url_parse { | ||
− | var %p = | + | var %p = /(?:^|[][()<>{}'"\s])((?:(?:irc|s?ftp|https?:)\/\/|www\d*\.)[^\s./]+\.(?:\[\S*?]|\(\S*?\)|\{\S*?}|[^][()<>{}'"\s]|['"](?!\s|$|[()\[\]<>]))++)/iS |
noop $regex($1,%p) | noop $regex($1,%p) | ||
return $regml(1) | return $regml(1) | ||
Line 125: | Line 174: | ||
; alias to store the given url into database file, and return color according to whether it's new, opened, or unopened in database | ; alias to store the given url into database file, and return color according to whether it's new, opened, or unopened in database | ||
alias -l url_log { | alias -l url_log { | ||
− | ; this first $iif is to append | + | ; this first $iif is to append "http://" in front of "www.", so "www.google.com" and "<nowiki>http://www.google.com</nowiki>" will be a same link, and not to be written twice |
; we'll assign the target channel/query into variable %t | ; we'll assign the target channel/query into variable %t | ||
; the $read will search the database file for the given url | ; the $read will search the database file for the given url | ||
− | var %url = | + | var %url = $iif(www* iswm $1,$+(<nowiki>http://,$1</nowiki>),$1) |
var %t = $iif($left($target,1) != $chr(35),query,$target) | var %t = $iif($left($target,1) != $chr(35),query,$target) | ||
− | var % | + | var %isOld = $hget(links.hash,%url) |
+ | |||
+ | ; if %isOld is empty (the link wasn't found from the file), write it in there and return color of "new link" & the line number the link was added to | ||
+ | ; also add the info to the hashtable | ||
+ | if (!%isOld) { | ||
+ | var %insertLine = $asctime(yyyy.mm.dd HH:nn:ss) $+($clr(03),$chr(31),%url,$chr(31),$clr()) $+($clr(07),$iif($nick,$nick,$me),$clr(08),@,$clr(07),%t,$clr()) | ||
+ | write $db %insertLine | ||
+ | hadd links.hash %url %insertLine | ||
− | + | return $url_color(new) $lines($db) | |
− | |||
− | |||
− | |||
} | } | ||
; otherwise, if the link was found, check if it has been opened via mirc (4th word will be !), return color of "opened link" | ; otherwise, if the link was found, check if it has been opened via mirc (4th word will be !), return color of "opened link" | ||
− | elseif ($gettok(% | + | elseif ($gettok(%isOld,4,32) == !) { |
− | return $url_color(opened) | + | return $url_color(opened) __old %isOld |
} | } | ||
; and if none of above, it's in the database, but you haven't opened it, return color of "old link" | ; and if none of above, it's in the database, but you haven't opened it, return color of "old link" | ||
else { | else { | ||
− | return $url_color(old) | + | return $url_color(old) __old %isOld |
} | } | ||
} | } | ||
Line 158: | Line 211: | ||
; filter with the content of editbox | ; filter with the content of editbox | ||
; timer to give a little delay for the filter (not filtering if writing fast), change the 200 (in milliseconds) to | ; timer to give a little delay for the filter (not filtering if writing fast), change the 200 (in milliseconds) to | ||
− | ; a | + | ; a bit higher value, if you're a slower writer. |
.timerURL -m 1 200 filter -cpfw $db @links $+(*,$editbox(@links),*) | .timerURL -m 1 200 filter -cpfw $db @links $+(*,$editbox(@links),*) | ||
} | } | ||
Line 171: | Line 224: | ||
; on hotlink to trigger on links, this first one is for doubleclick | ; on hotlink to trigger on links, this first one is for doubleclick | ||
− | + | on *$:HOTLINK:/((www.?\.|https?:\/\/|ftp:\/\/).)/i:*:{ | |
− | + | ; clean up the triggered url with $url_parse and append "http://" in front of "www." | |
− | ; clean up the triggered url with $url_parse and append | ||
; read the url info from database file, and if it doesn't have '!' as fourth token, add the '!' in there and write it back | ; read the url info from database file, and if it doesn't have '!' as fourth token, add the '!' in there and write it back | ||
; then open the url with url -n %url (change this, if you have your own alias for opening urls) | ; then open the url with url -n %url (change this, if you have your own alias for opening urls) | ||
var %url = $url_parse($1) | var %url = $url_parse($1) | ||
− | var %url = | + | var %url = $iif(www* iswm %url,$+(<nowiki>http://,%url</nowiki>),%url) |
+ | |||
+ | url -n %url | ||
+ | |||
var %oldurl = $read($db,w,$+(*,$chr(31),%url,$chr(31),*)) | var %oldurl = $read($db,w,$+(*,$chr(31),%url,$chr(31),*)) | ||
− | if ($gettok(%oldurl,4,32) != !) { write $+(-l,$readn) $db $instok(%oldurl,!,4,32) | + | |
− | + | if ($gettok(%oldurl,4,32) != !) { | |
+ | write $+(-l,$readn) $db $instok(%oldurl,!,4,32) | ||
+ | hadd links.hash %url $instok(%oldurl,!,4,32) | ||
+ | } | ||
} | } | ||
− | ; this second on hotlink is for the right click, shows the popup | + | ; this second on hotlink is for the right click, shows the popup (leave it even if you're not going to use the spopup.dll) |
− | + | on ^*$:HOTLINK:/((www.?\.|https?:\/\/|ftp:\/\/).)/i:*:{ | |
; check if the spopup.dll file is in the right place, if not, halt so it'll show the default popup | ; check if the spopup.dll file is in the right place, if not, halt so it'll show the default popup | ||
− | if (!$exists($spopupdll)) { halt } | + | if (!$exists($spopupdll)) { halt } |
− | ; check mouse | + | ; check if mouse button 2 have been pressed |
− | if ($mouse.key & 16) | + | if ($mouse.key & 16) { popup_url $url_parse($1) } |
− | |||
− | |||
} | } | ||
Line 201: | Line 257: | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
− | ; the path to spopup.dll | + | ; the path to spopup.dll (this default snipped uses the spopup.dll in the same folder where mirc.exe is located) |
− | alias -l spopupdll { return $qt(spopup.dll) } | + | alias -l spopupdll { return $qt($deltok($mircexe,-1,92) $+ \ $+ spopup.dll) } |
; the new popup to replace the original one with a dll | ; the new popup to replace the original one with a dll | ||
Line 209: | Line 265: | ||
; strip colors etc. from given url ($1), and find the url info from the database file | ; strip colors etc. from given url ($1), and find the url info from the database file | ||
var %url = $strip($1) | var %url = $strip($1) | ||
− | var %url2 = $ | + | var %url2 = $strip($hget(links.hash,%url)) |
; assign the info variables | ; assign the info variables | ||
var %datetime = $strip($gettok(%url2,1-2,32)) | var %datetime = $strip($gettok(%url2,1-2,32)) | ||
var %nickchan = $strip($gettok(%url2,4-,32)) | var %nickchan = $strip($gettok(%url2,4-,32)) | ||
− | var %nickchan = $iif($left(%nickchan,1) == !,$right(%nickchan,-2),%nickchan) | + | var %nickchan = $iif($left(%nickchan,1) == !,$right(%nickchan,-2),%nickchan) |
; show the popup | ; show the popup | ||
Line 231: | Line 287: | ||
; assign the popup selection into a variable | ; assign the popup selection into a variable | ||
− | var %c = $dll($spopupdll,popup,$mouse. | + | var %c = $dll($spopupdll,popup,$mouse.cx $mouse.cy 1) |
; check what the selection was | ; check what the selection was | ||
Line 239: | Line 295: | ||
elseif (%c == 3) { clipboard %datetime %nickchan %url } | elseif (%c == 3) { clipboard %datetime %nickchan %url } | ||
elseif (%c == 4) { echo -agi30 url info: %datetime %nickchan %url } | elseif (%c == 4) { echo -agi30 url info: %datetime %nickchan %url } | ||
− | elseif (%c == 7) { write $+(- | + | elseif (%c == 7) { elseif (%c == 7) { write $+(-dw*,%url,*) $db | LinkHash_Load } |
} | } | ||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
+ | ; | ||
+ | ; this section is for the title fetching (youtube only at this time) | ||
+ | ; you won't need this part if you don't want to use the title fetching funcitonality | ||
+ | ; | ||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
+ | |||
+ | ; this is the output handler alias that gets called from different parts of the script, depending on if we're dealing with an old title or new | ||
+ | alias titleOutput { | ||
+ | ; format the title, we'll need timers here to output text _after_ the link has been processed and is echoed | ||
+ | var %title = $replace($gettok($remtok($iif($4 == __new,$1-,$5-),!,1,32),5-,32),|,$!chr(124)) | ||
+ | |||
+ | ; %inputSendLink will be true if you pressed enter holding down ctrl key, and it will message the title to the channel | ||
+ | if (%inputSendLink) { | ||
+ | .timerYTTitle $+ _msg_ $+ $2 -m 1 1 msg $3 Youtube: %title | ||
+ | } | ||
+ | |||
+ | ; checking if the channel where the link was posted, is in %sendYTtitleChans variable, if so, sends the title to the channel | ||
+ | else if ($istok(%sendYTtitleChans,$3,32)) { | ||
+ | .timerYTTitle $+ _msg_ $+ $2 -m 1 1 msg $3 Youtube: %title | ||
+ | } | ||
+ | |||
+ | ; echo the title of the link in the channel for you to see it | ||
+ | .timerYTTitle $+ _echo_ $+ $2 -m 1 1 echo -t $3 Youtube: %title | ||
+ | } | ||
+ | |||
+ | ; a helper alias to clean HTML entities from the titles | ||
+ | alias stripHTMLEntities { | ||
+ | return $replace($1, ,$chr(160),",",<,<,>,>,&,&, $& | ||
+ | £, $chr(163), €, $chr(8364), ©, $chr(169), &trade, $chr(8482), ®, $chr(174)) | ||
+ | } | ||
+ | |||
+ | ; alias to handle different possible sources for the title (youtube only for now) | ||
+ | alias gettitle { | ||
+ | ; first we check if we already have the title in the log, if so, use a quick timer to echo it out after the link | ||
+ | if ($4 == __old) { | ||
+ | titleOutput $1- | ||
+ | return | ||
+ | } | ||
+ | |||
+ | ; get the title for youtube links, also put some info on the sockmark, $2 = youtube URL, $3- = rest of the info | ||
+ | else if ($1 == youtube) { | ||
+ | var %sock = yttitle. $+ $ticks | ||
+ | sockopen %sock gdata.youtube.com 80 | ||
+ | sockmark %sock $2 $3- | ||
+ | } | ||
+ | } | ||
+ | |||
+ | ; socket events for youtube - sockopen | ||
+ | on *:sockopen:yttitle.*:{ | ||
+ | if $sockerr { return } | ||
+ | |||
+ | noop $regex($gettok($sock($sockname).mark,1,32),/(\?v=|&v=|\/\d\/|\/embed\/|\/v\/|\.be\/)([a-zA-Z0-9\-\_]{11})/) | ||
+ | |||
+ | sockwrite -n $sockname GET /feeds/mobile/videos/ $+ $$regml(2) $+ ?v=2&prettyprint=true HTTP/1.1 | ||
+ | sockwrite -n $sockname Host: $sock($sockname).addr | ||
+ | sockwrite -n $sockname $crlf | ||
+ | } | ||
+ | |||
+ | ; socket events for youtube - sockread | ||
+ | on *:sockread:yttitle.*:{ | ||
+ | if $sockerr { return } | ||
+ | |||
+ | var %data | sockread %data | ||
+ | |||
+ | while ($sockbr) { | ||
+ | if (*<title>*</title>* iswm %data) { | ||
+ | ; get the title | ||
+ | var %title = $regsubex(%data,/(.*<title>|</title>.*)/g,) | ||
+ | |||
+ | ; send the title to titleOutput with other info | ||
+ | titleOutput youtube $gettok($sock($sockname).mark,1,32) $gettok($sock($sockname).mark,2,32) __new %title | ||
+ | |||
+ | ; if we set the linenumber info to the sockmark, we need to write the title into the DB file on that line | ||
+ | if ($gettok($sock($sockname).mark,3,32)) { | ||
+ | var %oldurl = $hget(links.hash,$gettok($sock($sockname).mark,1,32)) | ||
+ | write $+(-l,$v1) $db %oldurl %title | ||
+ | hadd links.hash $gettok($sock($sockname).mark,1,32) %oldurl %title | ||
+ | } | ||
+ | |||
+ | sockclose $sockname | ||
+ | return | ||
+ | } | ||
+ | sockread %data | ||
+ | } | ||
+ | } | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
Line 248: | Line 390: | ||
; basically you just need to run a line through $urlc() to color the links and log them | ; basically you just need to run a line through $urlc() to color the links and log them | ||
; you can add this into whatever event you like, ie. var %line = $urlc($1-) | echo %line | ; you can add this into whatever event you like, ie. var %line = $urlc($1-) | echo %line | ||
+ | ; this example also holds the if ($ctrlenter) { set %inputSendLink 1 } part, which is used in the title fetcher | ||
; | ; | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
Line 253: | Line 396: | ||
on *:INPUT:*: { | on *:INPUT:*: { | ||
; we will check that ctrl wasn't pressed while pressing enter, and that it's not a command | ; we will check that ctrl wasn't pressed while pressing enter, and that it's not a command | ||
− | if ($left($1,1) === $readini(mirc.ini,text,commandchar)) && (!$ctrlenter) { return } | + | if ($left($1,1) === $readini(mirc.ini,text,commandchar)) && (!$ctrlenter) { return } |
+ | |||
+ | ; check if ctrl was pressed while pressing enter, and store it in a variable (for sending title to the channel in case of a youtube link) | ||
+ | unset %inputSendLink | ||
+ | if ($ctrlenter) { set %inputSendLink 1 } | ||
; halt the default actions | ; halt the default actions | ||
Line 265: | Line 412: | ||
; then we have the echo | ; then we have the echo | ||
− | echo $color(own text) -at $+(<,$nick($chan,$me).pnick,>) %line | + | echo $color(own text) -at $+(<,$iif($chan,$nick($chan,$me).pnick,$me),>) %line |
} | } | ||
Line 271: | Line 418: | ||
; halt the default actions and assign $1- into a variable, and run it through $urlc() to color the links and log them | ; halt the default actions and assign $1- into a variable, and run it through $urlc() to color the links and log them | ||
haltdef | haltdef | ||
− | var %line = $urlc($1-) | + | var %line = $urlc($1-) |
; echo the text into a right channel, -m highlights the switchbar button with "message color", -t adds timestamp | ; echo the text into a right channel, -m highlights the switchbar button with "message color", -t adds timestamp | ||
− | echo $color(normal) - | + | echo $color(normal) -mlt $chan $+(<,$nick($chan,$nick).pnick,>) %line |
} | } | ||
Line 283: | Line 430: | ||
; echo the text into a right query | ; echo the text into a right query | ||
− | echo $color(normal) - | + | echo $color(normal) -mlt $nick $+(<,$nick,>) %line |
} | } | ||
− | |||
− | |||
− |
Latest revision as of 02:13, 11 December 2019
Screenshots:
Screenshot 1: Colored links
Screenshot 2: Links search ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; URL-logger with colored and underlined links by Cail at Quakenet -> #help.script ; ; $urlc -alias will color and underline links from the input, and log them into a file for later searching ; Tested and works on mIRC 6.2 and above (i recommend using >6.21 for $regsubex to work correctly) ; ; This script uses spopup.dll (OPTIONAL! you only need this if you want a new popup with info and some new features.), ; to replace mirc's builtin url-popup ; spopup.dll is made by Saturn, and you can get it from http://www.xise.nl/mirc/ ; NOTE! Depending on how your mIRC is set up, your working path might be mirc's root dir, or Users/AppData folder ; For example in Windows 7 the AppData folder would be: C:\Users\HappyUser\AppData\Roaming\mIRC ; Note this when placing the .dll somewhere and not giving full path in the script. ; ; Formats recognized links like: ; - "http://google.com" -> http://google.com ; - url('www.google.com'); -> www.google.com ; - (www.google.com/ahihi(kiaa)) -> www.google.com/ahihi(kiaa) ; ; And some more cleanups, and adds 'http://' in front of 'www.' for storing. ; so that www.google.com and http://www.google.com are treated as a same link, and stored only once ; ; Uses 3 different colors for coloring links: ; 1) new link - not found from the file ; 2) opened link - is found from the file, and you have opened it via mirc ; 3) old link - is found from the file, but you haven't opened it ; ; Fetches title of youtube video's: ; - Gets title of the video and stores it into the links.db (for searching) ; - Echo's the title under the link in chat ; - Hold down ctrl key when pressing enter if you post a link, to /msg the title into the channel ; - Fill %sendYTtitleChans with channels separated by spaces (eg. %sendYTtitleChans #chan1 #chan2) to automatically ; send the title into the channel when ever a youtube link is posted. ; ; Thanks to: ; - Saturn for the spopup.dll ; - Msmo for the cleanup regex ; ; ; UPDATE 06/07/2014: Performance update! ; - Added hashtables to be used on regular checks, speeding up the normal link flow, no more slowdowns with hundreds of thousands of links ; - Changed youtube title fetcher to use youtube API for faster download & faster parsing ; - Some bug fixes and general performance improvements ; UPDATE 14/06/2013: Added support for fetching and storing title from youtube links ; - fetches youtube video's title, stores it into the logfile, echoes the title on the channel ; - hold down ctrl key when pressing enter, when you post a link, to send the title as /msg to the channel (overrides %sendYTtitleChans variable) ; - set %sendYTtitleChans variable for channels you want to /msg the title automatically when a link is posted ; (for example: %sendYTtitleChans #channel1 #channel2 #channel3) would send the title into the channel on those 3 channels ; UPDATE 17/06/2007: Updated regex (fixed 'www.someurl.com/something's_here' to show correctly), added a timer with 200ms delay ; into the on keyup event (to prevent filtering while writing fast). ; UPDATE 23/03/2007: Changed on keydown -> on keyup, much more efficient now, won't need so much checks, and allows you to ; insert text infront/into the middle of the line. ; UPDATE 29/01/2007: added a regex into on keydown event to halt the script if something else than \S was pressed ; (now holding down shift/alt/ctrl doesn't affect it), and optimized the on keydown event a bit. ; UPDATE 18/01/2007: added on input event for the search (optional), rearranged the dll-stuff into same place, ; fixed a bug that didn't color some opened links without http:// (only www.) ; fixed if (!$exists($spopupdll)) { return } from linkpopup to 'halt' (now shows the original popup) ; added a $db alias to return the filename, users can choose their own path/filename for the file. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; $db returns the name of the database file, change this to whatever you want alias -l db { return $qt($deltok($mircexe,-1,92) $+ \ $+ links.db) } ; on start event for creating and loading the hash table on *:start:{ linkhash_load } alias linkhash_load { ; free the old hashtable if it exists, and hmake a new one if ($hget(links.hash)) { hfree links.hash } hmake links.hash 1000 ; filter links from DB file to the hashtable filter -fk $db LinkHash_copy * } alias linkhash_copy { tokenize 32 $1 hadd links.hash $strip($3) $1- } ; alias to open the links window, and filter all of the urls into it alias urllog { ; if the window isn't open, create it, -ea to create an editbox and activate the window ; filter will copy the lines from the file by a matchtext (* = everything), -fw = from File to Window, and -p = wrap the text if (!$window(@links)) { window -ea @links filter -fwp $db @links * } ; else the window is already open, so activate it else { window -a @links } } ; alias to return colorcodes for the script, change these values to whatever you like. ; new, old and opened are for echo text, log_link and log_info are for the @links window alias -l url_color { if ($1 == new) { return 12 } elseif ($1 == old) { return 6 } elseif ($1 == opened) { return 10 } elseif ($1 == log_link) { return 10 } elseif ($1 == log_info) { return 14 } } ; $clr alias to return $chr(3) and formatted color code, ie. $clr(3) == $+($chr(3),03) == ctrl+k 03 alias -l clr { if ($isid) { return $+($chr(3),$base($1,10,10,2)) $+ $iif($2,$+($chr(44),$base($2,10,10,2)),) } } ; this alias handles checking the input for links, looping through tokens (words in this case), and replacing links with colored ones alias urlc { if (!$isid) { return } var %string = $1- ; if the line even has links, useless to loop through it if there are no links if ($regex(%string,/(?:\b(?:www.?\.|https?:\/\/|s?ftp:\/\/).)/i)) { ; so the line has links, loop through tokens then var %x = 1 while (%x <= $numtok(%string,32)) { ; we'll assign the current token into a variable %tok, for easier use later ; and we'll run it through $url_parse, and assign the result into a variable %url ; (it'll be checked if it's a 'valid' url, and useless stuff be removed around it, if it's not an url the alias will return $null var %tok = $gettok(%string,%x,32) var %url = $url_parse(%tok) ; check if there is an url in variable %url if (%url) { ; $url_log will take care of storing the url into a database file, and return appropriate color (in $1) to use in coloring the link ; also returns the linenumber of newly added link (in $2) if we want to store the title for it ; and if we already have the title in the log, return that too in %titleLine var %indb = $url_log(%url) var %linkColor = $gettok(%indb,1,32) var %titleLine = $gettok(%indb,2-,32) ; now we color and underline the url and assign it into %newurl, (%indb will be holding the color code number) ; then we replace the url part of the token, so that from "url('www.something.com');" only the "www.something.com" part will be colored and underlined var %newurl = $+($clr(%linkColor),$chr(31),%url,$chr(31),$clr) var %newurl = $replace(%tok,%url,%newurl) ; and finally, we put the modified token back to the original string %string = $puttok(%string,%newurl,%x,32) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; OPTIONAL: GET YOUTUBE TITLE ; this part is for checking if it's a youtube link, and initiates the fetching of the video's title ; this can be commented out or removed if you don't want this functionality if (*youtube* iswm %url) || (*youtu.be* iswm %url) { getTitle youtube %url $iif($chan,$chan,$iif($target != $me,$target,$nick)) %titleLine } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END OF OPTIONAL } inc %x } } ; modified or not, return the string return %string } ; alias to trim the given url, returns $null if input isn't an url ; big thanks to Msmo on Quakenet for this regex alias -l url_parse { var %p = /(?:^|[][()<>{}'"\s])((?:(?:irc|s?ftp|https?:)\/\/|www\d*\.)[^\s./]+\.(?:\[\S*?]|\(\S*?\)|\{\S*?}|[^][()<>{}'"\s]|['"](?!\s|$|[()\[\]<>]))++)/iS noop $regex($1,%p) return $regml(1) } ; alias to store the given url into database file, and return color according to whether it's new, opened, or unopened in database alias -l url_log { ; this first $iif is to append "http://" in front of "www.", so "www.google.com" and "http://www.google.com" will be a same link, and not to be written twice ; we'll assign the target channel/query into variable %t ; the $read will search the database file for the given url var %url = $iif(www* iswm $1,$+(http://,$1),$1) var %t = $iif($left($target,1) != $chr(35),query,$target) var %isOld = $hget(links.hash,%url) ; if %isOld is empty (the link wasn't found from the file), write it in there and return color of "new link" & the line number the link was added to ; also add the info to the hashtable if (!%isOld) { var %insertLine = $asctime(yyyy.mm.dd HH:nn:ss) $+($clr(03),$chr(31),%url,$chr(31),$clr()) $+($clr(07),$iif($nick,$nick,$me),$clr(08),@,$clr(07),%t,$clr()) write $db %insertLine hadd links.hash %url %insertLine return $url_color(new) $lines($db) } ; otherwise, if the link was found, check if it has been opened via mirc (4th word will be !), return color of "opened link" elseif ($gettok(%isOld,4,32) == !) { return $url_color(opened) __old %isOld } ; and if none of above, it's in the database, but you haven't opened it, return color of "old link" else { return $url_color(old) __old %isOld } } ; this on keydown event triggers every time you press a key in @links window, ; and filters the database file into the window with the text in editbox ; so, performs a new search everytime you write something in that window, i like this kind of search, but you can make it with on input ; if you wish to use search with on input (searches when you press enter), disable #onKEYsearch -group (change 'on' -> 'off') #onKEYsearch on on *:KEYUP:@links:*:{ ; filter with the content of editbox ; timer to give a little delay for the filter (not filtering if writing fast), change the 200 (in milliseconds) to ; a bit higher value, if you're a slower writer. .timerURL -m 1 200 filter -cpfw $db @links $+(*,$editbox(@links),*) } #onKEYsearch end ; on input search for the @links window, if you want to use this instead of the on keydown, enable #onINPUTsearch -group (change 'off' -> 'on') #onINPUTsearch off on *:INPUT:@links: { filter -cpfw $db @links $+(*,$1-,*) } #onINPUTsearch end ; on hotlink to trigger on links, this first one is for doubleclick on *$:HOTLINK:/((www.?\.|https?:\/\/|ftp:\/\/).)/i:*:{ ; clean up the triggered url with $url_parse and append "http://" in front of "www." ; read the url info from database file, and if it doesn't have '!' as fourth token, add the '!' in there and write it back ; then open the url with url -n %url (change this, if you have your own alias for opening urls) var %url = $url_parse($1) var %url = $iif(www* iswm %url,$+(http://,%url),%url) url -n %url var %oldurl = $read($db,w,$+(*,$chr(31),%url,$chr(31),*)) if ($gettok(%oldurl,4,32) != !) { write $+(-l,$readn) $db $instok(%oldurl,!,4,32) hadd links.hash %url $instok(%oldurl,!,4,32) } } ; this second on hotlink is for the right click, shows the popup (leave it even if you're not going to use the spopup.dll) on ^*$:HOTLINK:/((www.?\.|https?:\/\/|ftp:\/\/).)/i:*:{ ; check if the spopup.dll file is in the right place, if not, halt so it'll show the default popup if (!$exists($spopupdll)) { halt } ; check if mouse button 2 have been pressed if ($mouse.key & 16) { popup_url $url_parse($1) } } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; here starts the functionality with the spopup.dll ; you won't need this part if you don't want to use the dll ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; the path to spopup.dll (this default snipped uses the spopup.dll in the same folder where mirc.exe is located) alias -l spopupdll { return $qt($deltok($mircexe,-1,92) $+ \ $+ spopup.dll) } ; the new popup to replace the original one with a dll alias -l popup_url { ; strip colors etc. from given url ($1), and find the url info from the database file var %url = $strip($1) var %url2 = $strip($hget(links.hash,%url)) ; assign the info variables var %datetime = $strip($gettok(%url2,1-2,32)) var %nickchan = $strip($gettok(%url2,4-,32)) var %nickchan = $iif($left(%nickchan,1) == !,$right(%nickchan,-2),%nickchan) ; show the popup dll $spopupdll clear dll $spopupdll add 1 0 0 open dll $spopupdll add 2 0 0 copy url dll $spopupdll add 3 0 0 copy info dll $spopupdll add 4 0 0 %datetime %nickchan ; show additional "remove item" if you are in the linklist if ($active == @links) { dll $spopupdll add 5 0 0 - dll $spopupdll add 6 0 16 remove url from db dll $spopupdll add 7 1 0 ok } ; assign the popup selection into a variable var %c = $dll($spopupdll,popup,$mouse.cx $mouse.cy 1) ; check what the selection was ; these are the ID's from the popup, 2) copy url 3) copy info 4) the info (echo's the info into active) 7) remove link (only in @links window) if (%c == 1) { url -n %url } elseif (%c == 2) { clipboard %url } elseif (%c == 3) { clipboard %datetime %nickchan %url } elseif (%c == 4) { echo -agi30 url info: %datetime %nickchan %url } elseif (%c == 7) { elseif (%c == 7) { write $+(-dw*,%url,*) $db | LinkHash_Load } } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; this section is for the title fetching (youtube only at this time) ; you won't need this part if you don't want to use the title fetching funcitonality ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; this is the output handler alias that gets called from different parts of the script, depending on if we're dealing with an old title or new alias titleOutput { ; format the title, we'll need timers here to output text _after_ the link has been processed and is echoed var %title = $replace($gettok($remtok($iif($4 == __new,$1-,$5-),!,1,32),5-,32),|,$!chr(124)) ; %inputSendLink will be true if you pressed enter holding down ctrl key, and it will message the title to the channel if (%inputSendLink) { .timerYTTitle $+ _msg_ $+ $2 -m 1 1 msg $3 Youtube: %title } ; checking if the channel where the link was posted, is in %sendYTtitleChans variable, if so, sends the title to the channel else if ($istok(%sendYTtitleChans,$3,32)) { .timerYTTitle $+ _msg_ $+ $2 -m 1 1 msg $3 Youtube: %title } ; echo the title of the link in the channel for you to see it .timerYTTitle $+ _echo_ $+ $2 -m 1 1 echo -t $3 Youtube: %title } ; a helper alias to clean HTML entities from the titles alias stripHTMLEntities { return $replace($1, ,$chr(160),",",<,<,>,>,&,&, $& £, $chr(163), €, $chr(8364), ©, $chr(169), &trade, $chr(8482), ®, $chr(174)) } ; alias to handle different possible sources for the title (youtube only for now) alias gettitle { ; first we check if we already have the title in the log, if so, use a quick timer to echo it out after the link if ($4 == __old) { titleOutput $1- return } ; get the title for youtube links, also put some info on the sockmark, $2 = youtube URL, $3- = rest of the info else if ($1 == youtube) { var %sock = yttitle. $+ $ticks sockopen %sock gdata.youtube.com 80 sockmark %sock $2 $3- } } ; socket events for youtube - sockopen on *:sockopen:yttitle.*:{ if $sockerr { return } noop $regex($gettok($sock($sockname).mark,1,32),/(\?v=|&v=|\/\d\/|\/embed\/|\/v\/|\.be\/)([a-zA-Z0-9\-\_]{11})/) sockwrite -n $sockname GET /feeds/mobile/videos/ $+ $$regml(2) $+ ?v=2&prettyprint=true HTTP/1.1 sockwrite -n $sockname Host: $sock($sockname).addr sockwrite -n $sockname $crlf } ; socket events for youtube - sockread on *:sockread:yttitle.*:{ if $sockerr { return } var %data | sockread %data while ($sockbr) { if (*<title>*</title>* iswm %data) { ; get the title var %title = $regsubex(%data,/(.*<title>|</title>.*)/g,) ; send the title to titleOutput with other info titleOutput youtube $gettok($sock($sockname).mark,1,32) $gettok($sock($sockname).mark,2,32) __new %title ; if we set the linenumber info to the sockmark, we need to write the title into the DB file on that line if ($gettok($sock($sockname).mark,3,32)) { var %oldurl = $hget(links.hash,$gettok($sock($sockname).mark,1,32)) write $+(-l,$v1) $db %oldurl %title hadd links.hash $gettok($sock($sockname).mark,1,32) %oldurl %title } sockclose $sockname return } sockread %data } } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; the rest of the script is a part of my how to make your own theme, and is only for an example usage of $urlc() ; basically you just need to run a line through $urlc() to color the links and log them ; you can add this into whatever event you like, ie. var %line = $urlc($1-) | echo %line ; this example also holds the if ($ctrlenter) { set %inputSendLink 1 } part, which is used in the title fetcher ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; on *:INPUT:*: { ; we will check that ctrl wasn't pressed while pressing enter, and that it's not a command if ($left($1,1) === $readini(mirc.ini,text,commandchar)) && (!$ctrlenter) { return } ; check if ctrl was pressed while pressing enter, and store it in a variable (for sending title to the channel in case of a youtube link) unset %inputSendLink if ($ctrlenter) { set %inputSendLink 1 } ; halt the default actions haltdef ; we'll put the line into a variable, using $urlc() to store & color links if there are any var %line = $urlc($1-) ; here is the part what we send as msg, we want to send $1- and not the modified variable .msg $target $1- ; then we have the echo echo $color(own text) -at $+(<,$iif($chan,$nick($chan,$me).pnick,$me),>) %line } on ^*:TEXT:*:#: { ; halt the default actions and assign $1- into a variable, and run it through $urlc() to color the links and log them haltdef var %line = $urlc($1-) ; echo the text into a right channel, -m highlights the switchbar button with "message color", -t adds timestamp echo $color(normal) -mlt $chan $+(<,$nick($chan,$nick).pnick,>) %line } on ^*:TEXT:*:?: { ; halt default actions, and set $1- into a variable, and run it through $urlc() haltdef var %line = $urlc($1-) ; echo the text into a right query echo $color(normal) -mlt $nick $+(<,$nick,>) %line }