Use custom stylesheets

Description

This is a simple script that enables the use of custom stylesheets (similar to the Stylish extension for Firefox).

  • All custom stylesheets should be in a single folder.
  • For every web site for which you want to have a custom stylesheet, you put it in that folder.
  • Every custom stylesheet must be named web_address.css (e.g. www.reddit.com.css)
  • If you want to use the script, you should add it to the commit_handler: 'spawn /path/to/script/change_style.sh'

Script

#/bin/bash
 
# Author: Jurica Bradaric <jbradaric at gmail.com> 
# A simple script to use custom stylesheets for websites.
# Similar to the Stylish extension for Firefox.
# I hope someone finds it useful. All comments and suggestions
# are welcome.
 
XDG_DATA_HOME=${XDG_DATA_HOME:-"$HOME/.local/share/"}
 
# Set the path to the .css files
# Every custom css style must be in a file named web_address.css
# e.g. reddit.com.css
STYLE_PATH=$XDG_DATA_HOME/uzbl/userstyles
 
STYLESHEET_SET=0
 
for i in $STYLE_PATH/*.css; do
    stylesheet=$(basename $i '.css')
    if [[ "$6" =~ "${stylesheet}" ]]; then
        #echo "set stylesheet_uri = file://$STYLE_PATH/${stylesheet}.css" >> "$4"
        echo "set stylesheet_uri = file://${STYLE_PATH}/${stylesheet}.css" | socat - unix-connect:$5
        STYLESHEET_SET=1
        break
    fi
done
 
if [ $STYLESHEET_SET -eq 0 ]; then
    echo "set stylesheet_uri = file://${STYLE_PATH}/default.css" | socat - unix-connect:$5
fi
 
exit 0

Alternative method

Instead of extenal script one can use setting in uzbl config file, e.g.:

set conf.d = $XDG_CONFIG_HOME/uzbl
@on_event LOAD_COMMIT set stylesheet_uri = file://@conf.d/css/\@(s=\@<location.host>\@.css; [ -e @conf.d/css/$s ] || s=default.css; echo $s)\@

in this example styles are located in ./css under uzbl config path

 
change_style.sh.txt · Last modified: 2010/05/12 03:46 by grimp3ur
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki