User Tools

Site Tools


zoom_in

Zoom In

A perl script to zoom in and out, and remember the zoom level next time you visit that page.

Script

#!/usr/bin/perl                                                                                                                                                                         
 
use strict;
use warnings;
 
my $config_dir = $ENV{HOME} . "/.config/uzbl"; # Edit this to where to store the file of zoom levels
my $file = $config_dir . "/zoom_levels";
my $fh;
my $url = $ARGV[0];
$url =~ s|^\w+://||;
$url =~ s|/.*||;
my $socket = $ARGV[1];
my $amount = $ARGV[2];
my @lines;
my $zoom;
if (-e $file) {
    open $fh, $file or die "Couldn't open '$file': $!";
    while (<$fh>) {
        chomp;
        my ($check, $z) = split /\s+/;
        if ($check eq $url) {
            $zoom = $z += $amount;
        }
        push @lines, "$check $z";
    }
    close $fh;
}
if (!defined $zoom) {
    $zoom = `uzblctrl -s $socket -c 'print \@zoom_level'`;
    if ($zoom == 0) { # If you don't set the zoom level, uzbl defaults it to 0 ???
        $zoom = 1.0;
    }
    $zoom += $amount;
    push @lines, "$url $zoom";
}
`uzblctrl -s $socket -c 'set zoom_level = $zoom'`;
open $fh, ">", $file or die "Cannot open $file: $!";
for my $line (@lines) {
    print $fh "$line\n";
}
close $fh;

Binding

To bind this script to your + and - keys use:

bind    +         = sh "$XDG_DATA_HOME/uzbl/scripts/zoom_in.pl \"$6\" $5 0.1"
bind    -         = sh "$XDG_DATA_HOME/uzbl/scripts/zoom_in.pl \"$6\" $5 -0.1"

The final argument is the amount to zoom by. To have it remember zoom levels set your load_commit_handler to zoom by 0.

set load_commit_handler = chain ... 'sh "$XDG_DATA_HOME/uzbl/scripts/zoom_in.pl \"$6\" $5 0.0"'
zoom_in.txt · Last modified: 2016/08/31 14:10 (external edit)