Skip to content

Instantly share code, notes, and snippets.

@AndrioCelos
Last active March 31, 2016 16:24
Show Gist options
  • Save AndrioCelos/3fe0d12e28f766ff0130 to your computer and use it in GitHub Desktop.
Save AndrioCelos/3fe0d12e28f766ff0130 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=m ($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
}
}
@un1versal
Copy link

why not submit it to be part of default KVIrc and close the related ticket?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment