aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/data/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'examples/data/scripts')
-rwxr-xr-xexamples/data/scripts/auth.py2
-rwxr-xr-xexamples/data/scripts/download.sh35
-rwxr-xr-xexamples/data/scripts/follow.sh2
-rwxr-xr-xexamples/data/scripts/formfiller.sh2
-rwxr-xr-xexamples/data/scripts/load_cookies.sh20
-rwxr-xr-xexamples/data/scripts/per-site-settings.py117
-rw-r--r--examples/data/scripts/pipermail.js71
-rwxr-xr-xexamples/data/scripts/scheme.py2
-rwxr-xr-xexamples/data/scripts/session.sh6
-rwxr-xr-xexamples/data/scripts/userscript.sh38
-rwxr-xr-xexamples/data/scripts/userscripts.sh8
-rw-r--r--examples/data/scripts/util/dmenu.sh12
-rwxr-xr-xexamples/data/scripts/uzbl-tabbed4
13 files changed, 239 insertions, 80 deletions
diff --git a/examples/data/scripts/auth.py b/examples/data/scripts/auth.py
index 9c1b4fc..592a2c6 100755
--- a/examples/data/scripts/auth.py
+++ b/examples/data/scripts/auth.py
@@ -46,7 +46,7 @@ def getText(authInfo, authHost, authRealm):
return rv, output
if __name__ == '__main__':
- rv, output = getText(sys.argv[8], sys.argv[9], sys.argv[10])
+ rv, output = getText(sys.argv[1], sys.argv[2], sys.argv[3])
if (rv == gtk.RESPONSE_OK):
print output;
else:
diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh
index b378a85..c410ad2 100755
--- a/examples/data/scripts/download.sh
+++ b/examples/data/scripts/download.sh
@@ -1,26 +1,25 @@
#!/bin/sh
-# just an example of how you could handle your downloads
-# try some pattern matching on the uri to determine what we should do
+#
+# uzbl's example configuration sets this script up as its download_handler.
+# when uzbl starts a download it runs this script.
+# if the script prints a file path to stdout, uzbl will save the download to
+# that path.
+# if nothing is printed to stdout, the download will be cancelled.
-shift 7
. $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_FILE"
+# the URL that is being downloaded
+uri=$1
-url="$1"
+# a filename suggested by the server or based on the URL
+suggested_filename=${2:-$(echo "$uri" | sed 's/\W/-/g')}
-http_proxy="$2"
-export http_proxy
+# the mimetype of the file being downloaded
+content_type=$3
-if [ -z "$url" ]; then
- echo "you must supply a url! ($url)"
- exit 1
-fi
+# the size of the downloaded file in bytes. this is not always accurate, since
+# the server might not have sent a size with its response headers.
+total_size=$4
-# only changes the dir for the $get sub process
-if echo "$url" | grep -E '.*\.torrent' >/dev/null; then
- ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url")
-else
- ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url")
-fi
+# just save the file to the default directory with the suggested name
+echo $UZBL_DOWNLOAD_DIR/$suggested_filename
diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh
index 2d666a2..d1560bf 100755
--- a/examples/data/scripts/follow.sh
+++ b/examples/data/scripts/follow.sh
@@ -3,8 +3,6 @@
# This script is just a wrapper around follow.js that lets us change uzbl's mode
# after a link is selected.
-shift 7
-
# if socat is installed then we can change Uzbl's input mode once a link is
# selected; otherwise we just select a link.
if ! which socat >/dev/null 2>&1; then
diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh
index 6e04573..c6822e6 100755
--- a/examples/data/scripts/formfiller.sh
+++ b/examples/data/scripts/formfiller.sh
@@ -53,8 +53,6 @@ MODELINE="> vim:ft=formfiller"
[ -d "$(dirname $UZBL_FORMS_DIR)" ] || exit 1
[ -d $UZBL_FORMS_DIR ] || mkdir $UZBL_FORMS_DIR || exit 1
-shift 7
-
action=$1
domain=$(echo $UZBL_URI | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/')
diff --git a/examples/data/scripts/load_cookies.sh b/examples/data/scripts/load_cookies.sh
new file mode 100755
index 0000000..17ec2ad
--- /dev/null
+++ b/examples/data/scripts/load_cookies.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+if [ "$1" != "" ]; then
+ cookie_file=$1
+else
+ cookie_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/cookies.txt
+fi
+
+awk -F \\t '
+BEGIN {
+ scheme["TRUE"] = "https";
+ scheme["FALSE"] = "http";
+}
+$0 ~ /^#HttpOnly_/ {
+printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", substr($1,length("#HttpOnly_"),length($1)), $3, $6, $7, scheme[$4], $5)
+}
+$0 !~ /^#/ {
+printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", $1, $3, $6, $7, scheme[$4], $5)
+}
+' $cookie_file
diff --git a/examples/data/scripts/per-site-settings.py b/examples/data/scripts/per-site-settings.py
new file mode 100755
index 0000000..89df4e6
--- /dev/null
+++ b/examples/data/scripts/per-site-settings.py
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+# Per-site settings plugin
+
+# Example configuration usage:
+#
+# @on_event LOAD_COMMIT spawn @scripts_dir/per-site-settings.py @data_home/uzbl/per-site-settings
+
+# Format of the settings file:
+#
+# <url>
+# <path>
+# <command>
+#
+# - url
+# May either be a regex, or literal. If literal, it will block any
+# subdomains as well.
+# - path
+# May either be a regex, or literal. If literal, it will block any
+# decendent paths as well.
+# - command
+# Given to uzbl verbatim.
+#
+# Matches are attempted on a literal match first.
+#
+# Any of the specifications can be repeated and acts as a fall-through to the
+# next level. Make sure indentation lines up locally. Any indentation addition
+# is considered as a fall through to the next level and any decrease is
+# considered a pop back (zero is always urls). This works because it's only 3
+# deep. Four and we'd have to keep track of things.
+
+import os
+import re
+import socket
+import stat
+import subprocess
+import tempfile
+import urlparse
+import sys
+
+
+def match_url(url, patt):
+ return url.endswith(patt) or re.match(patt, url)
+
+
+def match_path(path, patt):
+ return path.startswith(patt) or re.match(patt, path)
+
+
+def grep_url(url, path, fin):
+ entries = []
+ cur_indent = 0
+ passing = [False, False]
+ # 0 == url
+ # 1 == path
+ # 2 == command
+ state = 0
+ for line in fin:
+ raw = line.strip()
+
+ indent = len(line) - len(raw) - 1
+ if not indent:
+ # Reset state
+ passing = [False, False]
+ state = 0
+ else:
+ # previous level
+ if indent < cur_indent:
+ if state == 1:
+ passing[0] = False
+ elif state == 2:
+ passing[1] = False
+ state -= 1
+ # next level
+ elif cur_indent < indent:
+ state += 1
+
+ # parse the line
+ if state == 0:
+ if not passing[0] and match_url(url, raw):
+ passing[0] = True
+ elif state == 1 and passing[0]:
+ if not passing[1] and match_path(path, raw):
+ passing[1] = True
+ elif state == 2 and passing[1]:
+ entries.append(raw)
+
+ cur_indent = indent
+
+ return entries
+
+
+def write_to_socket(commands, sockpath):
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ sock.connect(sockpath)
+ for command in commands:
+ sock.send(command)
+ sock.close()
+
+
+if __name__ == '__main__':
+ sockpath = os.environ['UZBL_SOCKET']
+ url = urlparse.urlparse(os.environ['UZBL_URI'])
+ filepath = sys.argv[1]
+
+ mode = os.stat(filepath)[stat.ST_MODE]
+
+ if mode & stat.S_IEXEC:
+ fin = tempfile.TemporaryFile()
+ subprocess.Popen([filepath], stdout=fin).wait()
+ else:
+ fin = open(filepath, 'r')
+
+ commands = grep_url(url.hostname, url.path, fin)
+
+ fin.close()
+
+ write_to_socket(commands, sockpath)
diff --git a/examples/data/scripts/pipermail.js b/examples/data/scripts/pipermail.js
new file mode 100644
index 0000000..5ec4aa4
--- /dev/null
+++ b/examples/data/scripts/pipermail.js
@@ -0,0 +1,71 @@
+// this is a userscript inspired by "Pipermail Navigation Links" by Michael
+// Stone <http://userscripts.org/scripts/show/3174>.
+
+// it adds previous month/next month navigation links in pipermail mailing
+// list archives.
+
+// we wrap the whole thing in a function (that gets called immediately) so
+// that this script doesn't interfere with any javascript in the page.
+(function() {
+
+// figure out what page we're looking at right now
+var urlparts = document.location.toString().split("/");
+var currView = urlparts[urlparts.length-1].split("#")[0];
+var currDate = urlparts[urlparts.length-2].split("-");
+
+// figure out the URLs to the next month and previous month
+var months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July',
+ 'August', 'September', 'October', 'November', 'December' ];
+
+var thisMonth = currDate[1];
+var prevMonth;
+var nextMonth;
+
+var thisYear = currDate[0];
+var prevYear = thisYear;
+var nextYear = thisYear;
+
+if(thisMonth == 'January') {
+ prevMonth = "December";
+ nextMonth = "February";
+ prevYear = parseInt(thisYear) - 1;
+} else if(thisMonth == 'December') {
+ prevMonth = "November";
+ nextMonth = "January";
+ nextYear = parseInt(thisYear) + 1;
+} else {
+ var monthNum = months.indexOf(thisMonth);
+ prevMonth = months[monthNum - 1];
+ nextMonth = months[monthNum + 1];
+}
+
+var prevHref = "../" + prevYear + "-" + prevMonth + "/" + currView;
+var nextHref = "../" + nextYear + "-" + nextMonth + "/" + currView;
+
+// find the navigation header and footer
+var selector = "a[href='date.html#start']";
+
+// if we're on a "date" page then the date link isn't displayed
+if(currView == "date.html")
+ selector = "a[href='author.html#start']";
+
+var navLinks = document.querySelectorAll(selector);
+
+// append the prev/next links to the navigation header and footer
+for(var i = 0; i < navLinks.length; i++) {
+ var victim = navLinks[i].parentNode;
+
+ var prevEl = document.createElement("a");
+ prevEl.textContent = "[ prev month ]";
+ prevEl.href = prevHref;
+
+ var nextEl = document.createElement("a");
+ nextEl.textContent = "[ next month ]";
+ nextEl.href = nextHref;
+
+ victim.appendChild(prevEl);
+ victim.appendChild(document.createTextNode(" "));
+ victim.appendChild(nextEl);
+}
+
+})();
diff --git a/examples/data/scripts/scheme.py b/examples/data/scripts/scheme.py
index 0916466..4b0b7ca 100755
--- a/examples/data/scripts/scheme.py
+++ b/examples/data/scripts/scheme.py
@@ -13,7 +13,7 @@ def detach_open(cmd):
print 'USED'
if __name__ == '__main__':
- uri = sys.argv[8]
+ uri = sys.argv[1]
u = urlparse.urlparse(uri)
if u.scheme == 'mailto':
detach_open(['xterm', '-e', 'mail', u.path])
diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh
index 36e0c19..ee09cf2 100755
--- a/examples/data/scripts/session.sh
+++ b/examples/data/scripts/session.sh
@@ -30,12 +30,6 @@ fi
UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here.
-if [ $# -gt 1 ]; then
- # this script is being run from uzbl, rather than standalone
- # discard the uzbl arguments
- shift 7
-fi
-
scriptfile=$(readlink -f $0) # this script
act="$1"
diff --git a/examples/data/scripts/userscript.sh b/examples/data/scripts/userscript.sh
deleted file mode 100755
index fd95fdc..0000000
--- a/examples/data/scripts/userscript.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/sh
-
-if [ $# = "3" ]
-then
- UZBL_FIFO=$1
- UZBL_URI=$2
- SCRIPT=$3
-else
- 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 "$UZBL_URI" | 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 "$UZBL_URI" | grep -x "$EXCLUDE"; then
- SHOULD_RUN=false
- break
- fi
-done
-
-# Run the script
-if [ $SHOULD_RUN = true ]; then
- echo "script '$SCRIPT'" > "$UZBL_FIFO"
-fi
diff --git a/examples/data/scripts/userscripts.sh b/examples/data/scripts/userscripts.sh
deleted file mode 100755
index 4f76c90..0000000
--- a/examples/data/scripts/userscripts.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/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 "$UZBL_FIFO" "$UZBL_URI" "$SCRIPT"
-done
diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh
index da61cae..354d7d1 100644
--- a/examples/data/scripts/util/dmenu.sh
+++ b/examples/data/scripts/util/dmenu.sh
@@ -60,10 +60,16 @@ fi
if dmenu --help 2>&1 | grep -q '\[-xs\]'; then
DMENU_XMMS_ARGS="-xs"
DMENU_HAS_XMMS=1
+fi
- if echo $DMENU_OPTIONS | grep -q -w 'xmms'; then
- DMENU_ARGS="$DMENU_ARGS $DMENU_XMMS_ARGS"
- fi
+# Detect the tok patch
+if dmenu --help 2>&1 | grep -q '\[-t\]'; then
+ DMENU_XMMS_ARGS="-t"
+ DMENU_HAS_XMMS=1
+fi
+
+if echo $DMENU_OPTIONS | grep -q -w 'xmms'; then
+ DMENU_ARGS="$DMENU_ARGS $DMENU_XMMS_ARGS"
fi
# Detect the vertical patch
diff --git a/examples/data/scripts/uzbl-tabbed b/examples/data/scripts/uzbl-tabbed
index 0086c04..1d64436 100755
--- a/examples/data/scripts/uzbl-tabbed
+++ b/examples/data/scripts/uzbl-tabbed
@@ -452,7 +452,7 @@ class UzblInstance:
type, args = args.split(" ", 1)
if type == "TITLE_CHANGED":
self.title = args.strip()
- self.title_changed()
+ self.title_changed(False)
elif type == "VARIABLE_SET":
var, _, val = args.split(" ", 2)
@@ -485,6 +485,8 @@ class UzblInstance:
if var == "uri":
self.uri = val.strip()
self.parent.update_tablist()
+ elif type == "LOAD_COMMIT":
+ self.uri = args
elif type == "NEW_TAB":
self.parent.new_tab(args)
elif type == "NEW_BG_TAB":