From c255c6f9e23b8bb9b377ca830853b9c82d2156cd Mon Sep 17 00:00:00 2001 From: Stanislas Marquis Date: Fri, 15 May 2020 13:16:38 +0200 Subject: [PATCH] Expose/isolate main function of the script. --- urltitle.tcl | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/urltitle.tcl b/urltitle.tcl index d85ed48..c6c0f4f 100644 --- a/urltitle.tcl +++ b/urltitle.tcl @@ -100,9 +100,25 @@ namespace eval UrlTitle { } } - proc handler {nick host user chan text} { + proc getTitle {url} { variable httpsSupport variable htmlSupport + # enable https if supported + if {$httpsSupport} { + ::http::register https 443 [list UrlTitle::socket] + } + set title [UrlTitle::parse $url] + if {$htmlSupport} { + set title [::htmlparse::mapEscapes $title] + } + # unregister https if supported + if {$httpsSupport} { + ::http::unregister https + } + return $title + } + + proc handler {nick host user chan text} { variable delay variable last variable ignore @@ -114,18 +130,7 @@ namespace eval UrlTitle { ![regexp {://([^/:]*:([^/]*@|\d+(/|$))|.*/\.)} $word] && \ ![urlisignored $word]} { set last $unixtime - # enable https if supported - if {$httpsSupport} { - ::http::register https 443 [list UrlTitle::socket] - } - set urtitle [UrlTitle::parse $word] - if {$htmlSupport} { - set urtitle [::htmlparse::mapEscapes $urtitle] - } - # unregister https if supported - if {$httpsSupport} { - ::http::unregister https - } + set urtitle [UrlTitle::getTitle $word] if {$urtitle eq ""} { break }