aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/data/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'examples/data/scripts')
-rwxr-xr-xexamples/data/scripts/download.sh4
-rw-r--r--examples/data/scripts/follow.js11
-rwxr-xr-xexamples/data/scripts/follow.sh21
-rwxr-xr-xexamples/data/scripts/formfiller.sh13
-rw-r--r--examples/data/scripts/go_input.js27
-rwxr-xr-xexamples/data/scripts/go_input.sh20
-rwxr-xr-xexamples/data/scripts/history.sh2
-rwxr-xr-xexamples/data/scripts/insert_bookmark.sh6
-rwxr-xr-xexamples/data/scripts/instance-select-wmii.sh4
-rwxr-xr-xexamples/data/scripts/load_url_from_bookmarks.sh6
-rwxr-xr-xexamples/data/scripts/load_url_from_history.sh6
-rwxr-xr-xexamples/data/scripts/userscript.sh40
-rwxr-xr-xexamples/data/scripts/userscripts.sh8
-rw-r--r--examples/data/scripts/util/dmenu.sh2
-rwxr-xr-xexamples/data/scripts/uzbl-cookie-daemon44
-rwxr-xr-xexamples/data/scripts/uzbl-event-manager2
-rwxr-xr-xexamples/data/scripts/uzbl-tabbed25
17 files changed, 182 insertions, 59 deletions
diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh
index 7375535..606aa62 100755
--- a/examples/data/scripts/download.sh
+++ b/examples/data/scripts/download.sh
@@ -2,8 +2,8 @@
# just an example of how you could handle your downloads
# try some pattern matching on the uri to determine what we should do
-source $UZBL_UTIL_DIR/uzbl-args.sh
-source $UZBL_UTIL_DIR/uzbl-dir.sh
+. $UZBL_UTIL_DIR/uzbl-args.sh
+. $UZBL_UTIL_DIR/uzbl-dir.sh
# Some sites block the default wget --user-agent..
GET="wget --user-agent=Firefox --content-disposition --load-cookies=$UZBL_COOKIE_JAR"
diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js
index bcceb74..3a18b1b 100644
--- a/examples/data/scripts/follow.js
+++ b/examples/data/scripts/follow.js
@@ -127,12 +127,11 @@ function clickElem(item) {
removeAllHints();
if (item) {
var name = item.tagName;
- if (name == 'A') {
+ if (name == 'BUTTON') {
item.click();
- window.location = item.href;
} else if (name == 'INPUT') {
- var type = item.getAttribute('type').toUpperCase();
- if (type == 'TEXT' || type == 'FILE' || type == 'PASSWORD') {
+ var type = item.type.toUpperCase();
+ if (type == 'TEXT' || type == 'SEARCH' || type == 'PASSWORD') {
item.focus();
item.select();
} else {
@@ -166,7 +165,7 @@ function addFormElems() {
for (var f = 0; f < forms.length; f++) {
for (var e = 0; e < forms[f].elements.length; e++) {
var el = forms[f].elements[e];
- if (el && ['INPUT', 'TEXTAREA', 'SELECT'].indexOf(el.tagName) + 1 && isVisible(el) && elementInViewport(el)) {
+ if (el && ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'].indexOf(el.tagName) + 1 && isVisible(el) && elementInViewport(el)) {
res[0].push(el);
}
}
@@ -242,7 +241,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..b2e61ec 100755
--- a/examples/data/scripts/formfiller.sh
+++ b/examples/data/scripts/formfiller.sh
@@ -43,11 +43,12 @@ DMENU_LINES="3"
DMENU_PROMPT="Choose profile"
DMENU_OPTIONS="vertical resize"
-source $UZBL_UTIL_DIR/dmenu.sh
-source $UZBL_UTIL_DIR/editor.sh
-source $UZBL_UTIL_DIR/uzbl-args.sh
-source $UZBL_UTIL_DIR/uzbl-dir.sh
+. $UZBL_UTIL_DIR/dmenu.sh
+. $UZBL_UTIL_DIR/editor.sh
+. $UZBL_UTIL_DIR/uzbl-args.sh
+. $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/history.sh b/examples/data/scripts/history.sh
index 0cd2218..0561fe9 100755
--- a/examples/data/scripts/history.sh
+++ b/examples/data/scripts/history.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-source $UZBL_UTIL_DIR/uzbl-dir.sh
+. $UZBL_UTIL_DIR/uzbl-dir.sh
[ -w "$UZBL_HISTORY_FILE" ] || [ ! -a "$UZBL_HISTORY_FILE" ] || exit 1
diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh
index 9303b85..d99ff31 100755
--- a/examples/data/scripts/insert_bookmark.sh
+++ b/examples/data/scripts/insert_bookmark.sh
@@ -1,12 +1,12 @@
#!/bin/sh
-source $UZBL_UTIL_DIR/uzbl-args.sh
-source $UZBL_UTIL_DIR/uzbl-dir.sh
+. "$UZBL_UTIL_DIR"/uzbl-args.sh
+. "$UZBL_UTIL_DIR"/uzbl-dir.sh
[ -d "$UZBL_DATA_DIR" ] || exit 1
[ -w "$UZBL_BOOKMARKS_FILE" ] || [ ! -a "$UZBL_BOOKMARKS_FILE" ] || exit 1
-which zenity &>/dev/null || exit 2
+which zenity 2>&1 >/dev/null || exit 2
tags=$(zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URL:")
exitstatus=$?
diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh
index 967d7ad..19d04e8 100755
--- a/examples/data/scripts/instance-select-wmii.sh
+++ b/examples/data/scripts/instance-select-wmii.sh
@@ -13,7 +13,7 @@
DMENU_SCHEME="wmii"
-source $UZBL_UTIL_DIR/dmenu.sh
+. $UZBL_UTIL_DIR/dmenu.sh
case "$1" in
"list" )
@@ -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/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh
index ed1e2e8..9346526 100755
--- a/examples/data/scripts/load_url_from_bookmarks.sh
+++ b/examples/data/scripts/load_url_from_bookmarks.sh
@@ -5,9 +5,9 @@
DMENU_SCHEME="bookmarks"
DMENU_OPTIONS="xmms vertical resize"
-source "$UZBL_UTIL_DIR"/dmenu.sh
-source "$UZBL_UTIL_DIR"/uzbl-args.sh
-source "$UZBL_UTIL_DIR"/uzbl-dir.sh
+. "$UZBL_UTIL_DIR"/dmenu.sh
+. "$UZBL_UTIL_DIR"/uzbl-args.sh
+. "$UZBL_UTIL_DIR"/uzbl-dir.sh
[ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1
diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh
index 8582bc3..4499e7f 100755
--- a/examples/data/scripts/load_url_from_history.sh
+++ b/examples/data/scripts/load_url_from_history.sh
@@ -3,9 +3,9 @@
DMENU_SCHEME="history"
DMENU_OPTIONS="xmms vertical resize"
-source "$UZBL_UTIL_DIR"/dmenu.sh
-source "$UZBL_UTIL_DIR"/uzbl-args.sh
-source "$UZBL_UTIL_DIR"/uzbl-dir.sh
+. "$UZBL_UTIL_DIR"/dmenu.sh
+. "$UZBL_UTIL_DIR"/uzbl-args.sh
+. "$UZBL_UTIL_DIR"/uzbl-dir.sh
[ -r "$UZBL_HISTORY_FILE" ] || exit 1
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/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh
index 757e5cd..f789178 100644
--- a/examples/data/scripts/util/dmenu.sh
+++ b/examples/data/scripts/util/dmenu.sh
@@ -12,7 +12,7 @@ case "$DMENU_SCHEME" in
# Formfiller
"formfiller" )
NB="#0f0f0f"
- NF="4e7093"
+ NF="#4e7093"
SB="#003d7c"
SF="#3a9bff"
;;
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-event-manager b/examples/data/scripts/uzbl-event-manager
index ab13fbb..8ad3af7 100755
--- a/examples/data/scripts/uzbl-event-manager
+++ b/examples/data/scripts/uzbl-event-manager
@@ -825,7 +825,7 @@ if __name__ == "__main__":
add('-n', '--no-daemon',
dest='daemon_mode', action='store_false', default=True,
- help='daemonize the process')
+ help='do not daemonize the process')
add('-a', '--auto-close',
dest='auto_close', action='store_true', default=False,
diff --git a/examples/data/scripts/uzbl-tabbed b/examples/data/scripts/uzbl-tabbed
index 5bf802a..9e5d715 100755
--- a/examples/data/scripts/uzbl-tabbed
+++ b/examples/data/scripts/uzbl-tabbed
@@ -158,7 +158,7 @@ import atexit
import types
from gobject import io_add_watch, source_remove, timeout_add, IO_IN, IO_HUP
-from signal import signal, SIGTERM, SIGINT, SIGCHLD
+from signal import signal, SIGTERM, SIGINT
from optparse import OptionParser, OptionGroup
from traceback import print_exc
@@ -536,7 +536,6 @@ class UzblTabbed:
self._timers = {}
self._buffer = ""
self._killed = False
- self._processes = []
# A list of the recently closed tabs
self._closed = []
@@ -656,9 +655,6 @@ class UzblTabbed:
# Catch keyboard interrupts
signal(SIGINT, lambda signum, stack_frame: self.terminate(SIGINT))
- # Catch SIGCHLD
- signal(SIGCHLD, lambda signum, stack_frame: self.join_children())
-
try:
gtk.main()
@@ -678,15 +674,6 @@ class UzblTabbed:
raise
-
- def join_children(self):
- '''Find and remove zombie children processes.'''
-
- for p in self._processes:
- if p.poll() is not None:
- self._processes.remove(p)
-
-
def terminate(self, termsig=None):
'''Handle termination signals and exit safely and cleanly.'''
@@ -847,6 +834,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 +864,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]
@@ -1009,7 +1004,7 @@ class UzblTabbed:
cmd = ['uzbl-browser', '-n', name, '-s', str(sid),
'--connect-socket', self.socket_path, '--uri', uri]
- self._processes += [subprocess.Popen(cmd)] # TODO: do i need close_fds=True ?
+ gobject.spawn_async(cmd, flags=gobject.SPAWN_SEARCH_PATH)
uzbl = UzblInstance(self, tab, name, uri, title, switch)
SocketClient.instances_queue[name] = uzbl