diff options
Diffstat (limited to 'examples/data/scripts')
-rwxr-xr-x | examples/data/scripts/auth.py | 2 | ||||
-rwxr-xr-x | examples/data/scripts/download.sh | 14 | ||||
-rw-r--r-- | examples/data/scripts/follow.js | 40 | ||||
-rwxr-xr-x | examples/data/scripts/follow.sh | 22 | ||||
-rw-r--r-- | examples/data/scripts/formfiller.js | 35 | ||||
-rwxr-xr-x | examples/data/scripts/formfiller.sh | 24 | ||||
-rwxr-xr-x | examples/data/scripts/insert_temp.sh | 7 | ||||
-rwxr-xr-x | examples/data/scripts/load_url_from_temps.sh | 22 | ||||
-rw-r--r-- | examples/data/scripts/util/dmenu.sh | 7 | ||||
-rw-r--r-- | examples/data/scripts/util/uzbl-dir.sh | 13 |
10 files changed, 142 insertions, 44 deletions
diff --git a/examples/data/scripts/auth.py b/examples/data/scripts/auth.py index 592a2c6..49fa41e 100755 --- a/examples/data/scripts/auth.py +++ b/examples/data/scripts/auth.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python import gtk import sys diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index fe566ed..dbc9caf 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -1,9 +1,17 @@ #!/bin/sh # uzbl's example configuration sets this script up as its download_handler. -# when uzbl starts a download it runs this script. +# this script is run when uzbl encounters a URL that it can't display, and when +# a download is requested using the 'download' command. +# # 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. +# that path using it's internal downloader. +# +# if nothing is printed to stdout, the internal download will be cancelled. +# you could do your own download handling in your script that way. + +# if $5 is set, it is the path that was passed to uzbl's "download" command. +# we want to use that if it's available. +[ -n "$5" ] && echo "$5" && exit . "$UZBL_UTIL_DIR/uzbl-dir.sh" diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js index b7b0d82..5ecdcef 100644 --- a/examples/data/scripts/follow.js +++ b/examples/data/scripts/follow.js @@ -16,7 +16,16 @@ uzbldivid = 'uzbl_link_hints'; uzbl.follow = function() { // Export charset = arguments[0]; - newwindow = arguments[2]; + if (arguments[2] == 0 || arguments[2] == 'click') { + newwindow = false; + returnuri = false; + } else if (arguments[2] == 1 || arguments[2] == 'newwindow') { + newwindow = true; + returnuri = false; + } else if (arguments[2] == 'returnuri') { + newwindow = false; + returnuri = true; + } var keypress = arguments[1]; return arguments.callee.followLinks(keypress); @@ -126,19 +135,19 @@ uzbl.follow.generateHint = function(doc, el, label, top, left) { // but at least set the href of the link. (needs some improvements) uzbl.follow.clickElem = function(item) { if(!item) return; - var name = item.tagName; - if (name == 'INPUT') { - var type = item.getAttribute('type').toUpperCase(); - if (type == 'TEXT' || type == 'FILE' || type == 'PASSWORD') { + if (item instanceof HTMLInputElement) { + var type = item.type; + if (type == 'text' || type == 'file' || type == 'password') { item.focus(); item.select(); return "XXXEMIT_FORM_ACTIVEXXX"; } // otherwise fall through to a simulated mouseclick. - } else if (name == 'TEXTAREA' || name == 'SELECT') { + } else if (item instanceof HTMLTextAreaElement || item instanceof HTMLSelectElement) { item.focus(); - item.select(); + if(typeof item.select != 'undefined') + item.select(); return "XXXEMIT_FORM_ACTIVEXXX"; } @@ -169,9 +178,13 @@ uzbl.follow.reDrawHints = function(elems, chars) { elements.forEach(function(el, i) { var label = labels[i]; var pos = positions[i]; - var doc = uzbl.follow.getDocument(el); - var h = uzbl.follow.generateHint(doc, el, label, pos[0], pos[1]); - doc.hintdiv.appendChild(h); + try { + var doc = uzbl.follow.getDocument(el); + var h = uzbl.follow.generateHint(doc, el, label, pos[0], pos[1]); + doc.hintdiv.appendChild(h); + } catch (err) { + // Unable to attach label -> shrug it off and continue + } }); } @@ -222,7 +235,7 @@ uzbl.follow.followLinks = function(follow) { //var desc = '*[title], img[alt], applet[alt], area[alt], input[alt]'; //var image = 'img, input[type=image]'; - if(newwindow) + if(newwindow || returnuri) var res = this.query(uri); else var res = this.query(followable); @@ -237,6 +250,11 @@ uzbl.follow.followLinks = function(follow) { // clear all of our hints this.clearHints(); + if (returnuri) { + var uri = el.src || el.href; + return "XXXRETURNED_URIXXX" + uri + } + if (newwindow) { // we're opening a new window using the URL attached to this element var uri = el.src || el.href; diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh index 014793e..30d3775 100755 --- a/examples/data/scripts/follow.sh +++ b/examples/data/scripts/follow.sh @@ -1,13 +1,31 @@ #!/bin/sh # This scripts acts on the return value of followLinks in follow.js -case "$1" in +result=$1 +shift + +uriaction=$1 +shift + +case "$result" in XXXEMIT_FORM_ACTIVEXXX) # a form element was selected - printf 'event FORM_ACTIVE\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO" + printf 'event KEYCMD_CLEAR\n' > "$UZBL_FIFO" ;; XXXRESET_MODEXXX) # a link was selected, reset uzbl's input mode printf 'set mode=\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO" ;; + XXXRETURNED_URIXXX*) + uri=${result#XXXRETURNED_URIXXX} + + case "$uriaction" in + set) + printf 'uri '"$uri"'\n' | sed -e 's/@/\\@/' > "$UZBL_FIFO" + ;; + clipboard) + printf "$uri" | xclip + ;; + esac + printf 'set mode=\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO" esac diff --git a/examples/data/scripts/formfiller.js b/examples/data/scripts/formfiller.js index abf0162..a5fc9ee 100644 --- a/examples/data/scripts/formfiller.js +++ b/examples/data/scripts/formfiller.js @@ -1,24 +1,37 @@ uzbl.formfiller = { + inputTypeIsText: function(type) { + var types = [ 'text', 'password', 'search', 'email', 'url', + 'number', 'range', 'color', 'date', 'month', + 'week', 'time', 'datetime', 'datetime-local' ]; + + for(var i = 0; i < types.length; ++i) + if(types[i] == type) return true; + + return false; + } + + , + dump: function() { var rv = ''; var allFrames = new Array(window); - for ( f=0; f<window.frames.length; ++f ) { + + for ( var f = 0; f < window.frames.length; ++f ) { allFrames.push(window.frames[f]); } - for ( j=0; j<allFrames.length; ++j ) { + + for ( var j = 0; j < allFrames.length; ++j ) { try { var xp_res = allFrames[j].document.evaluate( '//input', allFrames[j].document.documentElement, null, XPathResult.ANY_TYPE,null ); var input; while ( input = xp_res.iterateNext() ) { - var type = (input.type?input.type:text); - if ( type == 'text' || type == 'password' || type == 'search' ) { - rv += '%' + escape(input.name) + '(' + type + '):' + input.value + '\n'; - } - else if ( type == 'checkbox' || type == 'radio' ) { - rv += '%' + escape(input.name) + '(' + type + '){' + escape(input.value) + '}:' + (input.checked?'1':'0') + '\n'; + if ( inputTypeIsText(input.type) ) { + rv += '%' + escape(input.name) + '(' + input.type + '):' + input.value + '\n'; + } else if ( input.type == 'checkbox' || input.type == 'radio' ) { + rv += '%' + escape(input.name) + '(' + input.type + '){' + escape(input.value) + '}:' + (input.checked?'1':'0') + '\n'; } } xp_res = allFrames[j].document.evaluate( @@ -39,12 +52,12 @@ uzbl.formfiller = { insert: function(fname, ftype, fvalue, fchecked) { fname = unescape(fname); var allFrames = new Array(window); - for ( f=0; f<window.frames.length; ++f ) { + for ( var f = 0; f < window.frames.length; ++f ) { allFrames.push(window.frames[f]); } - for ( j=0; j<allFrames.length; ++j ) { + for ( var j = 0; j < allFrames.length; ++j ) { try { - if ( ftype == 'text' || ftype == 'password' || ftype == 'search' || ftype == 'textarea' ) { + if ( uzbl.formfiller.inputTypeIsText(ftype) || ftype == 'textarea' ) { allFrames[j].document.getElementsByName(fname)[0].value = fvalue; } else if ( ftype == 'checkbox' ) { diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 3dc9dc4..394bfbd 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -39,7 +39,10 @@ GenForm () GetOption () { DMENU_SCHEME=formfiller - DMENU_PROMPT="choose profile" + + # util/dmenu.sh doesn't handle spaces in DMENU_PROMPT. a proper fix will be + # tricky. + DMENU_PROMPT="choose_profile" DMENU_LINES=4 . "$UZBL_UTIL_DIR/dmenu.sh" @@ -66,27 +69,28 @@ ParseFields () field = $0 sub ( /[^:]*:/, "", field ) - if ( parts[2] ~ /(text|password|search)/ ) - printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",0);\n", - parts[1], parts[2], field ) - - else if ( parts[2] ~ /(checkbox|radio)/ ) + if ( parts[2] ~ /^(checkbox|radio)$/ ) printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",%s);\n", parts[1], parts[2], parts[3], field ) - else if ( parts[2] == "textarea" ) { + else if ( parts[2] ~ /^textarea$/ ) { field = "" while (getline) { if ( /^%/ ) break sub ( /^\\/, "" ) gsub ( /"/, "\\\"" ) gsub ( /\\/, "\\\\" ) - field = field $0 "\\n" + field = field $0 "\\\\n" } printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",0);\n", parts[1], parts[2], field ) } + else + printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",0);\n", + parts[1], parts[2], field ) + + }' } @@ -116,7 +120,7 @@ Load () ParseProfile $option < "$file" \ | ParseFields \ - | sed 's/@/\\@/' \ + | sed 's/@/\\@/g' \ > "$UZBL_FIFO" } @@ -132,7 +136,7 @@ Once () test -e "$tmpfile" && ParseFields < "$tmpfile" \ - | sed 's/@/\\@' \ + | sed 's/@/\\@/g' \ > "$UZBL_FIFO" } diff --git a/examples/data/scripts/insert_temp.sh b/examples/data/scripts/insert_temp.sh new file mode 100755 index 0000000..7ed8d22 --- /dev/null +++ b/examples/data/scripts/insert_temp.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +. "$UZBL_UTIL_DIR/uzbl-dir.sh" + +>> "$UZBL_TEMPS_FILE" || exit 1 + +echo "$UZBL_URI $UZBL_TITLE" >> "$UZBL_TEMPS_FILE" diff --git a/examples/data/scripts/load_url_from_temps.sh b/examples/data/scripts/load_url_from_temps.sh new file mode 100755 index 0000000..b46687b --- /dev/null +++ b/examples/data/scripts/load_url_from_temps.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +DMENU_SCHEME="temps" +DMENU_OPTIONS="xmms vertical resize" + +. "$UZBL_UTIL_DIR/dmenu.sh" +. "$UZBL_UTIL_DIR/uzbl-dir.sh" + +[ -r "$UZBL_TEMPS_FILE" ] || exit 1 + +if [ -z "$DMENU_HAS_VERTICAL" ]; then + # because they are all after each other, just show the url, not their titles. + goto=$( awk '{ print $1 }' "$UZBL_TEMPS_FILE" | $DMENU ) +else + # show titles + goto=$( $DMENU < "$UZBL_TEMPS_FILE" | cut -d ' ' -f 1 ) +fi + +sed -i -e "\<^$goto <d" $UZBL_TEMPS_FILE + +[ -n "$goto" ] && echo "uri $goto" > "$UZBL_FIFO" +#[ -n "$goto" ] && echo "uri $goto" | socat - "unix-connect:$UZBL_SOCKET" diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index f0d1651..0b7272e 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -30,6 +30,13 @@ case "$DMENU_SCHEME" in SB="#ccffaa" SF="#303030" ;; + # Temps + "temps" ) + NB="#303030" + NF="khaki" + SB="#ccffaa" + SF="#303030" + ;; # Default * ) NB="#303030" diff --git a/examples/data/scripts/util/uzbl-dir.sh b/examples/data/scripts/util/uzbl-dir.sh index 3d28151..76a7055 100644 --- a/examples/data/scripts/util/uzbl-dir.sh +++ b/examples/data/scripts/util/uzbl-dir.sh @@ -9,11 +9,12 @@ UZBL_SOCKET_DIR=/tmp # Directories UZBL_DOWNLOAD_DIR="${XDG_DOWNLOAD_DIR:-$HOME}" -UZBL_FORMS_DIR="$UZBL_DATA_DIR/dforms" +UZBL_FORMS_DIR="${UZBL_FORMS_DIR:-$UZBL_DATA_DIR/dforms}" # Data files -UZBL_CONFIG_FILE="$UZBL_CONFIG_DIR/config" -UZBL_COOKIE_FILE="$UZBL_DATA_DIR/cookies.txt" -UZBL_BOOKMARKS_FILE="$UZBL_DATA_DIR/bookmarks" -UZBL_HISTORY_FILE="$UZBL_DATA_DIR/history" -UZBL_SESSION_FILE="$UZBL_DATA_DIR/browser-session" +UZBL_CONFIG_FILE="${UZBL_CONFIG_FILE:-$UZBL_CONFIG_DIR/config}" +UZBL_COOKIE_FILE="${UZBL_COOKIE_FILE:-$UZBL_DATA_DIR/cookies.txt}" +UZBL_BOOKMARKS_FILE="${UZBL_BOOKMARKS_FILE:-$UZBL_DATA_DIR/bookmarks}" +UZBL_TEMPS_FILE="${UZBL_TEMPS_FILE:-$UZBL_DATA_DIR/temps}" +UZBL_HISTORY_FILE="${UZBL_HISTORY_FILE:-$UZBL_DATA_DIR/history}" +UZBL_SESSION_FILE="${UZBL_SESSION_FILE:-$UZBL_DATA_DIR/browser-session}" |