answered
2015-08-04 21:56:43 +0200
As a rough workaround, I've made a bash script called "bro" which handles the following:
―Image loading ON/OFF.
―Javascript ON/OFF.
―Plugins ON/OFF.
It works by modifying the standard Mozilla's 'prefs.js' configuration file (Sailfish stock browser is based on Mozilla). That way, you don't need to enter about:config, accept warning, search, modify and save.
Drawbacks: contrary to "about:config" way, it doesn't allow to make changes on the fly. You must first close browser, then open a terminal, execute the script, finally re-run browser. You must evaluate what is more comfortable and fast. Anyway, if it's just a matter of turning images off, I would recommend Webcat browser.
I ain't a programmer and my code looks horrific. Anyway, to play safe, the script creates a backup before modifying browser's config file. More info, see script's help.
INSTALLING:
―Open a terminal or log into your Sailfish device through SSH.
―Create a 'bin' directory in your home:
mkdir ~/bin
―Download the ZIP file (link below), extract a file called "bro" and move it into that 'bin' directory.
―Make it executable:
chmod +x ~/bin/bro
―Type 'bro', 'bro -h', 'bro -pleaseIneedtoknowhowtocontrolthisone' or 'bro -whatever' for detailed help/instructions. Examples for the smart ones:
$ bro i
# Disable image loading
$ bro Ijp
# Enable image loading, disable javascript, disable plugins
Download link:
bro.zip
And that's the script:
#!/bin/bash
# This script changes Sailfish stock browser's config (Mozilla standard
# 'prefs.js' file, located in ~/.mozilla/mozembed/), so user can
# disable or enable images, javascript and plugins.
PREFS_FILE=${HOME}/.mozilla/mozembed/prefs.js
PREFS_IMG='user_pref("permissions.default.image", 2);'
PREFS_JS='user_pref("javascript.enabled", false);'
PREFS_PLUG='user_pref("plugin.disable", false);'
error_info() {
echo "Usage:"
echo $(sed 's_.*/\(.*\)_\1_' <<< $0) "[iI][jJ][pP]"
echo "I: load images"
echo "i: no images"
echo "J: turn javascript ON"
echo "j: turn javascript OFF"
echo "P: turn plugins ON"
echo "p: turn plugins OFF"
echo
echo "To sum up: uppercase turns ON, lowercase turns OFF."
echo
echo "Example: you want to load images, but keep"
echo "javascript and plugins blocked:"
echo "bro Ijp"
echo
echo "You just want to disable image loading:"
echo "bro i"
echo
echo "If two options are repeated (e.g. 'bro JiPI'),"
echo "the last one will take effect."
echo
echo "First time is executed, it creates a backup in"
echo "~/.mozilla/mozembed/prefs.js~"
echo "If something goes wrong, you can restore default settings by"
echo "typing (close Sailfish browser before):"
echo "cp ~/.mozilla/mozembed/prefs.js~ ~/.mozilla/mozembed/prefs.js"
echo
}
add() {
echo "$1" >> $PREFS_FILE
}
erase() {
sed -i '/'"$1"'/ s_.*__' $PREFS_FILE
}
# Backup
[[ ! -f ${PREFS_FILE}~ ]] && cp -a $PREFS_FILE ${PREFS_FILE}~
# Starting
if [[ $# -ne 1 ]] || [[ $(grep -i [^ijp] <<< $1) ]]; then
error_info
elif [[ $(ps aux | grep sailfish-browser | grep -v grep) ]]; then
echo "Sailfish browser is running. You must first"
echo "close it, then execute this script and finally"
echo "run it again to make changes effective."
echo
else
if [[ $(grep i <<< $1) ]]; then
[[ $(grep "$PREFS_IMG" $PREFS_FILE) ]] || add "$PREFS_IMG"
echo "Image loading is disabled"
fi
if [[ $(grep I <<< $1) ]]; then
[[ $(grep "$PREFS_IMG" $PREFS_FILE) ]] && erase "$PREFS_IMG"
echo "Image loading is enabled"
fi
if [[ $(grep j <<< $1) ]]; then
[[ $(grep "$PREFS_JS" $PREFS_FILE) ]] || add "$PREFS_JS"
echo "Javascript is disabled"
fi
if [[ $(grep J <<< $1) ]]; then
[[ $(grep "$PREFS_JS" $PREFS_FILE) ]] && erase "$PREFS_JS"
echo "Javascript is enabled"
fi
if [[ $(grep P <<< $1) ]]; then
[[ $(grep "$PREFS_PLUG" $PREFS_FILE) ]] || add "$PREFS_PLUG"
echo "Plugins are enabled"
fi
if [[ $(grep p <<< $1) ]]; then
[[ $(grep "$PREFS_PLUG" $PREFS_FILE) ]] && erase "$PREFS_PLUG"
echo "Plugins are disabled"
fi
fi
# This script tends to add a lot of blank lines over the time.
# Removing them. Sed is my friendo. Sed is your friendo.
sed -ni '/..*/ p' $PREFS_FILE