Skip to content

Instantly share code, notes, and snippets.

@Stanzilla
Forked from AndrioCelos/urlpopup.kvs
Last active March 31, 2016 16:25
Show Gist options
  • Save Stanzilla/9b881564eda628d830edd2ddcdff0b02 to your computer and use it in GitHub Desktop.
Save Stanzilla/9b881564eda628d830edd2ddcdff0b02 to your computer and use it in GitHub Desktop.
This is a KVIrc script that modifies the popup menu for URLs to include the page title. This means that there will be a delay before the menu appears, while the page is downloaded. Don't forget to disable the existing event handler.
event(OnURLLinkPopupRequest,URLpopup) {
http.asyncGet -m=1048576 -t=10 -w=h ($0, $file.localdir(tmp\\title-preview)) {
popup.show urlpopup $0 $1 $2 $3;
}
}
defpopup(urlpopup) {
prologue {
%:status = $0;
%:title_found = $false;
%:title = "";
%title_open = -1;
%title_close = -1;
if ($0 == 1) {
// Read in the file.
%data = $file.read($2, 1048576);
// Find the HTML title.
%title_open = $str.findfirst(%data, "<title>", $false, 0);
if (%title_open != -1)
%title_close = $str.findfirst(%data, "</title>", $false, $(%title_open + 7));
if (%title_open != -1 && %title_close != -1) {
%:title = $str.mid(%data, $(%title_open + 7), $(%title_close - %title_open - 7));
%:title_found = $true;
echo Page title: $k(2)%:title;
}
file.remove $2;
}
}
label(Page title:) (%:title_found)
label(%:title) (%:title_found)
label(No page title was found.) (%:status == 1 && !%:title_found)
label(The preview download failed.) (%:status != 1)
item(Open link,14) {
openurl $0
}
item($tr("Copy To Clipboard","defscript"),259) {
str.toClipboard $0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment