aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/config/config25
-rw-r--r--examples/data/scripts/follow.js15
-rwxr-xr-xexamples/data/scripts/follow.sh21
-rwxr-xr-xexamples/data/scripts/formfiller.sh5
-rw-r--r--examples/data/scripts/go_input.js27
-rwxr-xr-xexamples/data/scripts/go_input.sh20
-rwxr-xr-xexamples/data/scripts/insert_bookmark.sh4
-rwxr-xr-xexamples/data/scripts/instance-select-wmii.sh2
-rwxr-xr-xexamples/data/scripts/userscript.sh40
-rwxr-xr-xexamples/data/scripts/userscripts.sh8
-rwxr-xr-xexamples/data/scripts/uzbl-cookie-daemon44
-rwxr-xr-xexamples/data/scripts/uzbl-tabbed8
12 files changed, 192 insertions, 27 deletions
diff --git a/examples/config/config b/examples/config/config
index 847b4af..ef5c122 100644
--- a/examples/config/config
+++ b/examples/config/config
@@ -65,6 +65,9 @@ set authentication_handler = sync_spawn @scripts_dir/auth.py
# Load commit handlers
@on_event LOAD_COMMIT @set_status <span foreground="green">recv</span>
+# Userscript support. Add all scripts to $XDG_DATA_HOME/uzbl/userscripts
+#@on_event LOAD_COMMIT spawn @scripts_dir/userscripts.sh
+
# Load finish handlers
@on_event LOAD_FINISH @set_status <span foreground="gold">done</span>
@on_event LOAD_FINISH spawn @scripts_dir/history.sh
@@ -122,6 +125,7 @@ set useragent = Uzbl (Webkit @{WEBKIT_MAJOR}.@{WEBKIT_MINOR}.@{WEBKIT_MI
@modmap <Control> <Ctrl>
@modmap <ISO_Left_Tab> <Shift-Tab>
@modmap <space> <Space>
+@modmap <KP_Enter> <Enter>
#modkey_addition <Key1> <Key2> <Result>
@modkey_addition <Shift> <Ctrl> <Meta>
@@ -131,6 +135,7 @@ set useragent = Uzbl (Webkit @{WEBKIT_MAJOR}.@{WEBKIT_MINOR}.@{WEBKIT_MI
#ignore_key <glob>
@ignore_key <ISO_*>
@ignore_key <Shift>
+@ignore_key <Multi_key>
# --- Bind aliases -----------------------------------------------------------
@@ -189,8 +194,12 @@ set ebind = @mode_bind global,-insert
@cbind l = scroll horizontal 20
@cbind <Page_Up> = scroll vertical -100%
@cbind <Page_Down> = scroll vertical 100%
+@cbind <Ctrl>f = scroll vertical 100%
+@cbind <Ctrl>b = scroll vertical -100%
@cbind << = scroll vertical begin
@cbind >> = scroll vertical end
+@cbind <Home> = scroll vertical begin
+@cbind <End> = scroll vertical end
@cbind ^ = scroll horizontal begin
@cbind $ = scroll horizontal end
@cbind <Space> = scroll vertical end
@@ -254,8 +263,12 @@ set ebind = @mode_bind global,-insert
# Yanking & pasting binds
@cbind yu = sh 'echo -n $6 | xclip'
+@cbind yU = sh 'echo -n $8 | xclip' \@SELECTED_URI
@cbind yy = sh 'echo -n $7 | xclip'
+@cbind yY = sh 'echo -n $8 | xclip' \@SELECTED_URI
+# Clone current window
+@cbind c = sh 'uzbl-browser -u $6'
# Go the page from primary selection
@cbind p = sh 'echo "uri `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4'
# Go to the page in clipboard
@@ -266,7 +279,7 @@ set ebind = @mode_bind global,-insert
@bind <Shift-Insert> = sh 'echo "event INJECT_KEYCMD `xclip -o | sed s/\\\@/%40/g`" > $4'
# Bookmark inserting binds
-@cbind <Ctrl>b<tags:>_ = sh 'echo -e "$6 %s" >> $XDG_DATA_HOME/uzbl/bookmarks'
+@cbind <Ctrl>b<tags:>_ = sh 'echo `printf "$6 %s"` >> $XDG_DATA_HOME/uzbl/bookmarks'
# Or use a script to insert a bookmark.
@cbind B = spawn @scripts_dir/insert_bookmark.sh
@@ -280,7 +293,8 @@ set follow_hint_keys = 0123456789
#set follow_hint_keys = qwerty
#set follow_hint_keys = asdfghjkl;
#set follow_hint_keys = thsnd-rcgmvwb/;789aefijkopquxyz234
-@cbind fl* = script @scripts_dir/follow.js '@follow_hint_keys %s'
+@cbind fl* = spawn @scripts_dir/follow.sh "%s"
+@cbind gi = spawn @scripts_dir/go_input.sh
# Form filler binds
# This script allows you to configure (per domain) values to fill in form
@@ -300,7 +314,12 @@ set formfiller = spawn @scripts_dir/formfiller.sh
@cbind gN = event NEW_TAB_NEXT
@cbind go<uri:>_ = event NEW_TAB %s
@cbind gO<uri:>_ = event NEW_TAB_NEXT %s
-@cbind gY = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4'
+@cbind gy = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4'
+@cbind gY = sh 'echo "event NEW_TAB_NEXT `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4'
+
+# Clone current tab
+@cbind gd = sh 'echo "event NEW_TAB $6" > $4'
+@cbind gD = sh 'echo "event NEW_TAB_NEXT $6" > $4'
# Closing / resting
@cbind gC = exit
diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js
index bcceb74..eacd52f 100644
--- a/examples/data/scripts/follow.js
+++ b/examples/data/scripts/follow.js
@@ -130,17 +130,26 @@ function clickElem(item) {
if (name == 'A') {
item.click();
window.location = item.href;
+ return "XXXRESET_MODEXXX";
} else if (name == 'INPUT') {
- var type = item.getAttribute('type').toUpperCase();
- if (type == 'TEXT' || type == 'FILE' || type == 'PASSWORD') {
+ var type;
+ try {
+ type = item.getAttribute('type').toUpperCase();
+ } catch(err) {
+ type = 'TEXT';
+ }
+ if (type == 'TEXT' || type == 'SEARCH' || type == 'PASSWORD') {
item.focus();
item.select();
+ return "XXXEMIT_FORM_ACTIVEXXX";
} else {
item.click();
+ return "XXXRESET_MODEXXX";
}
} else if (name == 'TEXTAREA' || name == 'SELECT') {
item.focus();
item.select();
+ return "XXXEMIT_FORM_ACTIVEXXX";
} else {
item.click();
window.location = item.href;
@@ -242,7 +251,7 @@ function followLinks(follow) {
var oldDiv = doc.getElementById(uzbldivid);
var leftover = [[], []];
if (s.length == len && linknr < elems[0].length && linknr >= 0) {
- clickElem(elems[0][linknr]);
+ return clickElem(elems[0][linknr]);
} else {
for (var j = 0; j < elems[0].length; j++) {
var b = true;
diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh
new file mode 100755
index 0000000..ba59575
--- /dev/null
+++ b/examples/data/scripts/follow.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+config=$1;
+shift
+pid=$1;
+shift
+xid=$1;
+shift
+fifo=$1;
+shift
+socket=$1;
+shift
+url=$1;
+shift
+title=$1;
+shift
+
+case $(echo 'script @scripts_dir/follow.js "@{follow_hint_keys} '$1'"' | socat - unix-connect:$socket) in
+ *XXXEMIT_FORM_ACTIVEXXX*) echo 'event FORM_ACTIVE' | socat - unix-connect:$socket ;;
+ *XXXRESET_MODEXXX*) echo 'set mode=' | socat - unix-connect:$socket ;;
+esac
diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh
index 19147a8..6982f9a 100755
--- a/examples/data/scripts/formfiller.sh
+++ b/examples/data/scripts/formfiller.sh
@@ -48,6 +48,7 @@ source $UZBL_UTIL_DIR/editor.sh
source $UZBL_UTIL_DIR/uzbl-args.sh
source $UZBL_UTIL_DIR/uzbl-dir.sh
+RAND=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -c 1-5)
MODELINE="> vim:ft=formfiller"
[ -d "$(dirname $UZBL_FORMS_DIR)" ] || exit 1
@@ -125,7 +126,7 @@ if [ "$action" = 'load' ]; then
if [ $(cat $UZBL_FORMS_DIR/$domain | grep "!profile" | wc -l) -gt 1 ]; then
menu=$(cat $UZBL_FORMS_DIR/$domain | \
sed -n 's/^!profile=\([^[:blank:]]\+\)/\1/p')
- option=$(echo -e -n "$menu" | $DMENU)
+ option=$(printf "$menu" | $DMENU)
fi
# Remove comments
@@ -174,7 +175,7 @@ elif [ "$action" = "once" ]; then
else
if [ "$action" = 'new' -o "$action" = 'add' ]; then
[ "$action" = 'new' ] && echo "$MODELINE" > $UZBL_FORMS_DIR/$domain
- echo "!profile=NAME_THIS_PROFILE$RANDOM" >> $UZBL_FORMS_DIR/$domain
+ echo "!profile=NAME_THIS_PROFILE$RAND" >> $UZBL_FORMS_DIR/$domain
#
# 2. and 3. line (tr -d and sed) are because, on gmail login for example,
# <input > tag is splited into lines
diff --git a/examples/data/scripts/go_input.js b/examples/data/scripts/go_input.js
new file mode 100644
index 0000000..557671f
--- /dev/null
+++ b/examples/data/scripts/go_input.js
@@ -0,0 +1,27 @@
+var elements = document.querySelectorAll("textarea, input" + [
+ ":not([type='button'])",
+ ":not([type='checkbox'])",
+ ":not([type='hidden'])",
+ ":not([type='image'])",
+ ":not([type='radio'])",
+ ":not([type='reset'])",
+ ":not([type='submit'])"].join(""));
+function gi() {
+ if (elements) {
+ var el, i = 0;
+ while((el = elements[i++])) {
+ var style=getComputedStyle(el, null);
+ if (style.display !== 'none' && style.visibility === 'visible') {
+ if (el.type === "file") {
+ el.click();
+ }
+ else {
+ el.focus();
+ }
+ return "XXXEMIT_FORM_ACTIVEXXX";
+ }
+ }
+ }
+}
+
+gi();
diff --git a/examples/data/scripts/go_input.sh b/examples/data/scripts/go_input.sh
new file mode 100755
index 0000000..c873dd8
--- /dev/null
+++ b/examples/data/scripts/go_input.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+config=$1;
+shift
+pid=$1;
+shift
+xid=$1;
+shift
+fifo=$1;
+shift
+socket=$1;
+shift
+url=$1;
+shift
+title=$1;
+shift
+
+case $(echo 'script @scripts_dir/go_input.js' | socat - unix-connect:$socket) in
+ *XXXEMIT_FORM_ACTIVEXXX*) echo 'event FORM_ACTIVE' | socat - unix-connect:$socket ;;
+esac
diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh
index 18f643f..acef37e 100755
--- a/examples/data/scripts/insert_bookmark.sh
+++ b/examples/data/scripts/insert_bookmark.sh
@@ -5,7 +5,7 @@ source $UZBL_UTIL_DIR/uzbl-dir.sh
[ -d "$UZBL_DATA_DIR" ] || exit 1
[ -w "$UZBL_BOOKMARKS_FILE" ] || exit 1
-which zenity &>/dev/null || exit 2
+which zenity 2>&1 >/dev/null || exit 2
# replace tabs, they are pointless in titles and we want to use tabs as delimiter.
title=$(echo "$UZBL_TITLE" | sed 's/\t/ /')
entry=$(zenity --entry --text="Add bookmark. add tags after the '\t', separated by spaces" --entry-text="$UZBL_URL $title\t")
@@ -15,5 +15,5 @@ url=$(echo $entry | awk '{print $1}')
# TODO: check if already exists, if so, and tags are different: ask if you want to replace tags
echo "$entry" >/dev/null #for some reason we need this.. don't ask me why
-echo -e "$entry" >> $UZBL_BOOKMARKS_FILE
+printf "$entry\n" >> $UZBL_BOOKMARKS_FILE
true
diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh
index 967d7ad..e70a143 100755
--- a/examples/data/scripts/instance-select-wmii.sh
+++ b/examples/data/scripts/instance-select-wmii.sh
@@ -23,7 +23,7 @@ case "$1" in
label=$(wmiir read /client/$i/label)
list="$list$i : $label\n"
done
- window=$(echo -e "$list" | $DMENU | cut -d ' ' -f1)
+ window=$(printf "$list\n" | $DMENU | cut -d ' ' -f1)
wmiir xwrite /tag/sel/ctl "select client $window"
;;
"next" )
diff --git a/examples/data/scripts/userscript.sh b/examples/data/scripts/userscript.sh
new file mode 100755
index 0000000..33a24ae
--- /dev/null
+++ b/examples/data/scripts/userscript.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+if [ $# = "3" ]
+then
+ fifo="$1"
+ url="$2"
+ SCRIPT="$3"
+else
+ fifo="$4"
+ url="$6"
+ SCRIPT="$8"
+fi
+
+# Extract metadata chunk
+META="`sed -ne '/^\s*\/\/\s*==UserScript==\s*$/,/^\s*\/\/\s*==\/UserScript==\s*$/p' "$SCRIPT"`"
+SHOULD_RUN=false # Assume this script will not be included
+# Loop over all include rules
+for INCLUDE in `echo "$META" | grep "^\s*\/\/\s*@include"`; do
+ # Munge into grep pattern
+ INCLUDE="`echo "$INCLUDE" | sed -e 's/^\s*\/\/\s*@include\s*//' -e 's/\./\\\\./g' -e 's/\*/.*/g' -e 's/[\r\n]//g'`"
+ if echo "$url" | grep -x "$INCLUDE"; then
+ SHOULD_RUN=true
+ break
+ fi
+done
+
+# Loop over all exclude rules
+for EXCLUDE in `echo "$META" | grep "^\s*\/\/\s*@exclude"`; do
+ # Munge into grep pattern
+ EXCLUDE="`echo "$EXCLUDE" | sed -e 's/^\s*\/\/\s*@exclude\s*//' -e 's/\./\\\\./g' -e 's/\*/.*/g' -e 's/[\r\n]//g'`"
+ if echo "$url" | grep -x "$EXCLUDE"; then
+ SHOULD_RUN=false
+ break
+ fi
+done
+
+# Run the script
+if [ $SHOULD_RUN = true ]; then
+ echo "script '$SCRIPT'" > "$fifo"
+fi
diff --git a/examples/data/scripts/userscripts.sh b/examples/data/scripts/userscripts.sh
new file mode 100755
index 0000000..8896224
--- /dev/null
+++ b/examples/data/scripts/userscripts.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+scripts_dir="$XDG_DATA_HOME/uzbl/userscripts"
+
+for SCRIPT in $(grep -rlx "\s*//\s*==UserScript==\s*" "$scripts_dir")
+do
+ $XDG_DATA_HOME/uzbl/scripts/userscript.sh "$4" "$6" "$SCRIPT"
+done
diff --git a/examples/data/scripts/uzbl-cookie-daemon b/examples/data/scripts/uzbl-cookie-daemon
index ed88de4..0b9bef9 100755
--- a/examples/data/scripts/uzbl-cookie-daemon
+++ b/examples/data/scripts/uzbl-cookie-daemon
@@ -436,18 +436,26 @@ class CookieMonster:
daemon_timeout = config['daemon_timeout']
echo("listening on %r" % config['cookie_socket'])
+ connections = []
+
while self._running:
# This line tells the socket how many pending incoming connections
# to enqueue at once. Raising this number may or may not increase
# performance.
self.server_socket.listen(1)
- if bool(select.select([self.server_socket], [], [], 1)[0]):
- client_socket, _ = self.server_socket.accept()
- self.handle_request(client_socket)
+ r, w, x = select.select([self.server_socket]+connections, [], [], 1)
+
+ for socket in r:
+ if self.server_socket == socket:
+ client_socket, _ = socket.accept()
+ connections.append(client_socket)
+ else:
+ if not self.handle_request(socket):
+ # connection was closed, forget about the client socket
+ connections.remove(socket)
+
self.last_request = time.time()
- client_socket.close()
- continue
if daemon_timeout:
# Checks if the daemon has been idling for too long.
@@ -462,7 +470,7 @@ class CookieMonster:
# Receive cookie request from client.
data = client_socket.recv(8192)
if not data:
- return
+ return False
# Cookie argument list in packet is null separated.
argv = data.split("\0")
@@ -471,17 +479,17 @@ class CookieMonster:
# Catch the EXIT command sent to kill running daemons.
if action == "EXIT":
self._running = False
- return
+ return False
# Catch whitelist RELOAD command.
elif action == "RELOAD":
self.reload_whitelist()
- return
+ return True
# Return if command unknown.
elif action not in ['GET', 'PUT']:
error("unknown command %r." % argv)
- return
+ return True
# Determine whether or not to print cookie data to terminal.
print_cookie = (config['verbose'] and not config['daemon_mode'])
@@ -499,13 +507,14 @@ class CookieMonster:
req = urllib2.Request(uri)
if action == "GET":
- self.jar.add_cookie_header(req)
- if req.has_header('Cookie'):
- cookie = req.get_header('Cookie')
- client_socket.send(cookie)
- if print_cookie:
- print cookie
-
+ self.jar._policy._now = self._now = int(time.time())
+ cookies = self.jar._cookies_for_request(req)
+ attrs = self.jar._cookie_attrs(cookies)
+ if attrs:
+ cookie = "; ".join(attrs)
+ client_socket.send(cookie)
+ if print_cookie:
+ print cookie
else:
client_socket.send("\0")
@@ -515,10 +524,13 @@ class CookieMonster:
print cookie
self.put_cookie(req, cookie)
+ client_socket.send("\0")
if print_cookie:
print
+ return True
+
def put_cookie(self, req, cookie=None):
'''Put a cookie in the cookie jar.'''
diff --git a/examples/data/scripts/uzbl-tabbed b/examples/data/scripts/uzbl-tabbed
index 5bf802a..42837d3 100755
--- a/examples/data/scripts/uzbl-tabbed
+++ b/examples/data/scripts/uzbl-tabbed
@@ -847,6 +847,8 @@ class UzblTabbed:
# Commands ( [] = optional, {} = required )
# new [uri]
# open new tab and head to optional uri.
+ # newbg [uri]
+ # open a new tab in the background
# close [tab-num]
# close current tab or close via tab id.
# next [n-tabs]
@@ -875,6 +877,12 @@ class UzblTabbed:
else:
self.new_tab()
+ elif cmd[0] == "newbg":
+ if len(cmd) == 2:
+ self.new_tab(cmd[1], switch=False)
+ else:
+ self.new_tab(switch=False)
+
elif cmd[0] == "newfromclip":
uri = subprocess.Popen(['xclip','-selection','clipboard','-o'],\
stdout=subprocess.PIPE).communicate()[0]