User Tools

Site Tools


view-site-images

Table of Contents

View Images

Shows all images from the currently viewed website pretty formated and resized in either the same or a new uzbl instance.

This script is meant to demonstrate JavaScript substitution and html-mode in a real world example.

Usage

Save the script below to a file and execute it.
See the comments for how to customize the behaviour and appearence.

NOTE: You will at least have to customize SOCKET and FIFO

Script

#!/bin/bash
#
# (c) 2009, Robert Manea <rot DOT manea AT gmail DOT com>
#
# Display all images of the currently viewed site
#

# Modify, these should probably be setable as cl arguments
#
SOCKET=/tmp/uzbl_socket_main
FIFO=/tmp/uzbl_fifo_main

#path to uzblctrl
#
UCTL=uzblctrl
#path to uzblcat
#
UCAT=uzblcat

# Preferences
#
IMAGES_PER_ROW=4
IMAGE_WIDTH=150
IMAGE_HEIGHT=90

#----------------------------------------------------------------------


IMAGE_CNT=$($UCTL -s $SOCKET -c 'print @<document.images.length-1>@')
SITE_URL=$($UCTL -s $SOCKET -c 'print @<location.href>@')


# retrieve image links
i=0
for url in $($UCTL -s $SOCKET -c 'print @<var res=[]; for(var i=0;i<document.images.length;i++){res.push(document.images[i].src);} res.join(" ")>@')
do
    IMG[$((i++))]="$url"
done

# construct the page holding the images
#
(
cat << EOHTML
<HTML><BODY><h2>Images on <br><a href="$SITE_URL">$SITE_URL</a>:</h2>
<TABLE border=5 rules=all frame=box 
cellspacing="20" cellpadding="20%">
<tr>
EOHTML

for i in $(seq 0 $IMAGE_CNT)
do
    [ $(($i % $IMAGES_PER_ROW)) -eq 0 ] &&  echo '</tr><tr>'
    cat << EOHTML
        <td><a href="${IMG[$i]}">
        <img src="${IMG[$i]}" width="$IMAGE_WIDTH" height="$IMAGE_HEIGHT"/>
        </a></td>
EOHTML
done 

echo '</tr></table>' \
     '</BODY></HTML>'

) | $UCAT > $FIFO         # open in existing instance
#) | $UCAT | uzbl -c -      # display in new uzbl instance
view-site-images.txt · Last modified: 2016/08/31 14:10 (external edit)