aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/config/config21
-rw-r--r--examples/config/style.css6
-rw-r--r--examples/data/scripts/follow.js194
-rwxr-xr-xexamples/data/scripts/follow.sh13
-rw-r--r--examples/data/scripts/formfiller.js25
-rwxr-xr-xexamples/data/scripts/formfiller.sh20
-rw-r--r--examples/data/scripts/go_input.js2
-rwxr-xr-xexamples/data/scripts/go_input.sh4
-rwxr-xr-xexamples/data/scripts/load_cookies.sh2
-rwxr-xr-xexamples/data/scripts/session.sh1
10 files changed, 185 insertions, 103 deletions
diff --git a/examples/config/config b/examples/config/config
index 385a60b..77686a0 100644
--- a/examples/config/config
+++ b/examples/config/config
@@ -28,8 +28,6 @@ set on_set = request ON_SET
set modmap = request MODMAP
# request IGNORE_KEY <glob>
set ignore_key = request IGNORE_KEY
-# request MODKEY_ADDITION <key1> <key2> <keyn> <result>
-set modkey_addition = request MODKEY_ADDITION
# request TOGGLE_MODES <mode1> <mode2> ... <moden>
set toggle_modes = request TOGGLE_MODES
@@ -44,6 +42,7 @@ set scripts_dir = @data_home/uzbl:@prefix/share/uzbl/examples/data:scripts
# These handlers can't be moved to the new event system yet as we don't
# support events that can wait for a response from a script.
set scheme_handler = sync_spawn @scripts_dir/scheme.py
+#set request_handler = sync_spawn @scripts_dir/request.py
set authentication_handler = sync_spawn @scripts_dir/auth.py
set download_handler = sync_spawn @scripts_dir/download.sh
@@ -145,6 +144,16 @@ set useragent = Uzbl (Webkit @{WEBKIT_MAJOR}.@{WEBKIT_MINOR}) (@(+uname
# Drop google analytics tracking cookies (applied after whitelists if any)
#request BLACKLIST_COOKIE name '^__utm.$'
+# === SSL related configuration ==============================================
+
+# Set it to certificates store of your distribution, or your own CAfile.
+set ssl_ca_file = /etc/ssl/certs/ca-certificates.crt
+set ssl_verify = 1
+# Command to toggle ssl_verify value:
+@cbind !ssl = chain 'toggle ssl_verify' 'reload'
+# Example SSL error handler:
+@on_event LOAD_ERROR js var patt=new RegExp('SSL handshake failed'); if (patt.test('%3')) {alert ('%3');}
+
# === Key binding configuration ==============================================
# --- Internal modmapping and ignoring ---------------------------------------
@@ -240,6 +249,8 @@ set ebind = @mode_bind global,-insert
@cbind ^ = scroll horizontal begin
@cbind $ = scroll horizontal end
@cbind <Space> = scroll vertical end
+@cbind G<Go To:>_ = scroll vertical %r!
+@cbind _G<Go To:>_ = scroll horizontal %r!
# Navigation binds
@cbind b = back
@@ -251,12 +262,12 @@ set ebind = @mode_bind global,-insert
# Zoom binds
@cbind + = zoom_in
@cbind - = zoom_out
-@cbind T = toggle_zoom_type
+@cbind T = toggle zoom_type
@cbind 1 = set zoom_level = 1.0
@cbind 2 = set zoom_level = 2.0
# Appearance binds
-@cbind t = toggle_status
+@cbind t = toggle show_status
# Page searching binds
@cbind /* = search %s
@@ -349,6 +360,8 @@ set follow_hint_keys = 0123456789
@cbind FL* = spawn @scripts_dir/follow.sh \@< uzbl.follow("\@follow_hint_keys", "%s", 'returnuri') >\@ clipboard
@cbind fi = spawn @scripts_dir/go_input.sh
+@cbind '* = spawn @scripts_dir/follow.sh \@< uzbl.follow.followTextContent("%s", 'click') >\@
+
# Form filler binds
# This script allows you to configure (per domain) values to fill in form
# fields (eg login information) and to fill in these values automatically.
diff --git a/examples/config/style.css b/examples/config/style.css
index a368aa0..b50b87c 100644
--- a/examples/config/style.css
+++ b/examples/config/style.css
@@ -25,4 +25,10 @@
color: black !important;
}
+.uzbl-follow-text-match {
+ outline: 2px solid invert;
+ background: #333 !important;
+ color: white !important;
+}
+
/* vim:set et ts=4: */
diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js
index 5ecdcef..88f80f2 100644
--- a/examples/data/scripts/follow.js
+++ b/examples/data/scripts/follow.js
@@ -15,16 +15,14 @@ uzbldivid = 'uzbl_link_hints';
uzbl.follow = function() {
// Export
- charset = arguments[0];
+ uzbl.follow.charset = arguments[0];
+
if (arguments[2] == 0 || arguments[2] == 'click') {
- newwindow = false;
- returnuri = false;
+ uzbl.follow.mode = 'click';
} else if (arguments[2] == 1 || arguments[2] == 'newwindow') {
- newwindow = true;
- returnuri = false;
+ uzbl.follow.mode = 'newwindow';
} else if (arguments[2] == 'returnuri') {
- newwindow = false;
- returnuri = true;
+ uzbl.follow.mode = 'returnuri';
}
var keypress = arguments[1];
@@ -110,7 +108,18 @@ uzbl.follow.elementInViewport = function(el) {
// by this script in the given document.
uzbl.follow.removeHints = function(doc) {
var elements = doc.getElementById(uzbldivid);
- if (elements) elements.parentNode.removeChild(elements);
+ if (elements)
+ elements.parentNode.removeChild(elements);
+
+ // this returns a live NodeList, which is super-annoying when we to try
+ // to remove the class.
+ var followTextMatches = doc.getElementsByClassName('uzbl-follow-text-match');
+ var matches = [];
+ for(var i = 0; i < followTextMatches.length; ++i)
+ matches.push(followTextMatches[i]);
+
+ for(var i = 0; i < matches.length; ++i)
+ matches[i].classList.remove('uzbl-follow-text-match');
}
// Clears all hints in every document
@@ -129,26 +138,32 @@ uzbl.follow.generateHint = function(doc, el, label, top, left) {
return hint;
}
-// Here we choose what to do with an element if we
-// want to "follow" it. On form elements we "select"
-// or pass the focus, on links we try to perform a click,
-// but at least set the href of the link. (needs some improvements)
+// this is pointlessly duplicated in uzbl.formfiller
+uzbl.follow.textInputTypes = [
+ 'text', 'password', 'search', 'email', 'url', 'number', 'range', 'color',
+ 'date', 'month', 'week', 'time', 'datetime', 'datetime-local'
+];
+
+// this is pointlessly duplicated in uzbl.formfiller
+uzbl.follow.inputTypeIsText = function(type) {
+ return uzbl.follow.textInputTypes.indexOf(type) >= 0;
+}
+
+// Here we choose what to do with an element that's been selected.
+// On text form elements we focus and select the content. On other
+// elements we simulate a mouse click.
uzbl.follow.clickElem = function(item) {
if(!item) return;
- 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.
+ if (item instanceof HTMLInputElement && uzbl.follow.inputTypeIsText(item.type)) {
+ item.focus();
+ item.select();
+ return "XXXFORM_ACTIVEXXX";
} else if (item instanceof HTMLTextAreaElement || item instanceof HTMLSelectElement) {
item.focus();
if(typeof item.select != 'undefined')
item.select();
- return "XXXEMIT_FORM_ACTIVEXXX";
+ return "XXXFORM_ACTIVEXXX";
}
// simulate a mouseclick to activate the element
@@ -159,9 +174,7 @@ uzbl.follow.clickElem = function(item) {
}
// Draw all hints for all elements passed.
-uzbl.follow.reDrawHints = function(elems, chars) {
- var elements = elems.map(function(pair) { return pair[0] });
- var labels = elems.map(function(pair) { return pair[1].substring(chars) });
+uzbl.follow.reDrawHints = function(elements, len) {
// we have to calculate element positions before we modify the DOM
// otherwise the elementPosition call slows way down.
var positions = elements.map(uzbl.follow.elementPosition);
@@ -171,13 +184,15 @@ uzbl.follow.reDrawHints = function(elems, chars) {
if (!doc.body) return;
doc.hintdiv = doc.createElement('div');
doc.hintdiv.id = uzbldivid;
- if(newwindow) doc.hintdiv.className = "new-window";
+ if(uzbl.follow.mode == 'newwindow')
+ doc.hintdiv.className = "new-window";
doc.body.appendChild(doc.hintdiv);
});
elements.forEach(function(el, i) {
- var label = labels[i];
+ var label = uzbl.follow.intToLabel(i, len);
var pos = positions[i];
+
try {
var doc = uzbl.follow.getDocument(el);
var h = uzbl.follow.generateHint(doc, el, label, pos[0], pos[1]);
@@ -197,19 +212,24 @@ uzbl.follow.labelLength = function(n) {
n -= 1; // Our highest key will be n-1
while(n) {
keylen += 1;
- n = Math.floor(n / charset.length);
+ n = Math.floor(n / uzbl.follow.charset.length);
}
return keylen;
}
-// pass: number
-// returns: label
-uzbl.follow.intToLabel = function(n) {
+// converts an integer 'n' to a string of length 'len' composed of
+// characters selected from uzbl.follow.charset.
+uzbl.follow.intToLabel = function(n, len) {
var label = '';
do {
- label = charset.charAt(n % charset.length) + label;
- n = Math.floor(n / charset.length);
+ label = uzbl.follow.charset.charAt(n % uzbl.follow.charset.length) + label;
+ n = Math.floor(n / uzbl.follow.charset.length);
} while(n);
+
+ for (var x = label.length; x < len; x++) {
+ label = uzbl.follow.charset.charAt(0) + label;
+ }
+
return label;
}
@@ -218,67 +238,91 @@ uzbl.follow.intToLabel = function(n) {
uzbl.follow.labelToInt = function(label) {
var n = 0;
for(var i = 0; i < label.length; ++i) {
- n *= charset.length;
- n += charset.indexOf(label[i]);
+ n *= uzbl.follow.charset.length;
+ n += uzbl.follow.charset.indexOf(label[i]);
}
return n;
}
-// Put it all together
-uzbl.follow.followLinks = function(follow) {
- var s = follow.split('');
- var linknr = this.labelToInt(follow);
+uzbl.follow.findMatchingHintId = function(elems, str) {
+ var linknr = this.labelToInt(str);
+
+ var len = this.labelLength(elems.length);
+ if (str.length == len && linknr < elems.length && linknr >= 0) {
+ // an element has been selected!
+ var el = elems[linknr];
+ return [el];
+ }
+
+ return elems.filter(function(el, i) {
+ // return elements whose labels begin with the given str
+ var label = uzbl.follow.intToLabel(i, len);
+ return label.slice(0, str.length) == str;
+ });
+}
+
+uzbl.follow.getInterestingElements = function() {
var followable = 'a, area, textarea, select, input:not([type=hidden]), button, *[onclick]';
var uri = 'a, area, frame, iframe';
//var focusable = 'a, area, textarea, select, input:not([type=hidden]), button, frame, iframe, applet, object';
//var desc = '*[title], img[alt], applet[alt], area[alt], input[alt]';
//var image = 'img, input[type=image]';
- if(newwindow || returnuri)
- var res = this.query(uri);
+ if(uzbl.follow.mode == 'newwindow' || uzbl.follow.mode == 'returnuri')
+ var elems = this.query(uri);
else
- var res = this.query(followable);
+ var elems = this.query(followable);
- var elems = res.filter(uzbl.follow.elementInViewport);
- var len = this.labelLength(elems.length);
+ return elems.filter(uzbl.follow.elementInViewport);
+}
- if (s.length == len && linknr < elems.length && linknr >= 0) {
- // an element has been selected!
- var el = elems[linknr];
+uzbl.follow.elementSelected = function(el) {
+ // clear all of our hints
+ this.clearHints();
+
+ if (uzbl.follow.mode == 'returnuri') {
+ var uri = el.src || el.href;
+ return "XXXRETURNED_URIXXX" + uri
+ } else if (uzbl.follow.mode == 'newwindow') {
+ // we're opening a new window using the URL attached to this element
+ var uri = el.src || el.href;
+ if(uri.match(/javascript:/)) return;
+ return "XXXNEW_WINDOWXXX " + uri;
+ } else {
+ // we're just going to click the element
+ return this.clickElem(el);
+ }
+}
- // clear all of our hints
- this.clearHints();
+uzbl.follow.followTextContent = function(str) {
+ str = str.toUpperCase();
- if (returnuri) {
- var uri = el.src || el.href;
- return "XXXRETURNED_URIXXX" + uri
- }
+ var matching = [];
- if (newwindow) {
- // we're opening a new window using the URL attached to this element
- var uri = el.src || el.href;
- if(uri.match(/javascript:/)) return;
- window.open(uri);
- return "XXXRESET_MODEXXX"
- }
+ var elems = uzbl.follow.getInterestingElements();
+ elems.forEach(function(el) {
+ // do a case-insensitive match on element content
+ if(el.textContent.toUpperCase().match(str)) {
+ el.classList.add('uzbl-follow-text-match');
+ matching.push(el);
+ } else {
+ el.classList.remove('uzbl-follow-text-match');
+ }
+ });
- // we're just going to click the element
- return this.clickElem(el);
- }
+ if(matching.length == 1)
+ return uzbl.follow.elementSelected(matching[0]);
+}
- var leftover = [];
- for (var j = 0; j < elems.length; j++) {
- var b = true;
- var label = this.intToLabel(j);
- var n = label.length;
- for (n; n < len; n++)
- label = charset.charAt(0) + label;
- for (var k = 0; k < s.length; k++)
- b = b && label.charAt(k) == s[k];
- if (b)
- leftover.push([elems[j], label]);
- }
+uzbl.follow.followLinks = function(str) {
+ var elems = uzbl.follow.getInterestingElements();
+ var leftover = uzbl.follow.findMatchingHintId(elems, str);
- this.reDrawHints(leftover, s.length);
+ if(leftover.length == 1)
+ return uzbl.follow.elementSelected(leftover[0]);
+ else {
+ var len = this.labelLength(elems.length) - str.length;
+ this.reDrawHints(leftover, len);
+ }
}
diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh
index 30d3775..de126eb 100755
--- a/examples/data/scripts/follow.sh
+++ b/examples/data/scripts/follow.sh
@@ -1,22 +1,23 @@
#!/bin/sh
-# This scripts acts on the return value of followLinks in follow.js
+# This scripts acts on the return value of followLinks in follow.js
result=$1
shift
-uriaction=$1
-shift
-
case "$result" in
- XXXEMIT_FORM_ACTIVEXXX)
+ XXXFORM_ACTIVEXXX)
# a form element was selected
- printf 'event KEYCMD_CLEAR\n' > "$UZBL_FIFO"
+ echo 'event KEYCMD_CLEAR' > "$UZBL_FIFO"
;;
XXXRESET_MODEXXX)
# a link was selected, reset uzbl's input mode
printf 'set mode=\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO"
;;
+ XXXNEW_WINDOWXXX*)
+ printf "set mode=\nevent KEYCMD_CLEAR\nevent NEW_WINDOW $@\n" > "$UZBL_FIFO"
+ ;;
XXXRETURNED_URIXXX*)
+ uriaction=$1
uri=${result#XXXRETURNED_URIXXX}
case "$uriaction" in
diff --git a/examples/data/scripts/formfiller.js b/examples/data/scripts/formfiller.js
index 4470661..06db648 100644
--- a/examples/data/scripts/formfiller.js
+++ b/examples/data/scripts/formfiller.js
@@ -1,14 +1,16 @@
uzbl.formfiller = {
- inputTypeIsText: function(type) {
- var types = [ 'text', 'password', 'search', 'email', 'url',
- 'number', 'range', 'color', 'date', 'month',
- 'week', 'time', 'datetime', 'datetime-local' ];
+ // this is pointlessly duplicated in uzbl.follow
+ textInputTypes: [
+ '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;
+ // this is pointlessly duplicated in uzbl.follow
+ inputTypeIsText: function(type) {
+ return uzbl.formfiller.textInputTypes.indexOf(type) >= 0;
}
,
@@ -27,6 +29,9 @@ uzbl.formfiller = {
for( var k = 0; k < inputs.length; ++k ) {
var input = inputs[k];
+ if ( ! input.name ) {
+ continue
+ }
if ( uzbl.formfiller.inputTypeIsText(input.type) ) {
rv += '%' + escape(input.name) + '(' + input.type + '):' + input.value + '\n';
} else if ( input.type == 'checkbox' || input.type == 'radio' ) {
@@ -37,8 +42,10 @@ uzbl.formfiller = {
var textareas = allFrames[j].document.getElementsByTagName("textarea");
for( var k = 0; k < textareas.length; ++k ) {
var textarea = textareas[k];
- rv += '%' + escape(textarea.name) + '(textarea):\n' + textarea.value.replace(/\n%/g,"\n\\%") + '\n%\n';
- rv += '%' + escape(textarea.name) + '(textarea):\n' + textarea.value.replace(/\n\\/g,"\n\\\\").replace(/\n%/g,"\n\\%") + '%\n';
+ if ( ! textarea.name ) {
+ continue
+ }
+ rv += '%' + escape(textarea.name) + '(textarea):\n' + textarea.value.replace(/(^|\n)\\/g,"$1\\\\").replace(/(^|\n)%/g,"$1\\%") + '\n%\n';
}
}
catch (err) { }
diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh
index 394bfbd..52d6ec6 100755
--- a/examples/data/scripts/formfiller.sh
+++ b/examples/data/scripts/formfiller.sh
@@ -63,6 +63,9 @@ ParseFields ()
awk '/^%/ {
sub ( /%/, "" )
+ gsub ( /\\/, "\\\\\\\\" )
+ gsub ( /@/, "\\@" )
+ gsub ( /"/, "\\\"" )
split( $0, parts, /\(|\)|\{|\}/ )
@@ -73,15 +76,24 @@ ParseFields ()
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 ( /^\\/, "" )
+ # JavaScript escape
+ gsub ( /\\/, "\\\\\\\\" )
gsub ( /"/, "\\\"" )
- gsub ( /\\/, "\\\\" )
- field = field $0 "\\\\n"
+ # To support the possibility of the last line of the textarea
+ # not being terminated by a newline, we add the newline here.
+ # The "if (field)" is so that this does not happen in the first
+ # iteration.
+ if (field) field = field "\\n"
+ field = field $0
}
+ # Uzbl escape
+ gsub ( /\\/, "\\\\\\\\", field )
+ gsub ( /@/, "\\@", field )
printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",0);\n",
parts[1], parts[2], field )
}
@@ -120,7 +132,6 @@ Load ()
ParseProfile $option < "$file" \
| ParseFields \
- | sed 's/@/\\@/g' \
> "$UZBL_FIFO"
}
@@ -136,7 +147,6 @@ Once ()
test -e "$tmpfile" &&
ParseFields < "$tmpfile" \
- | sed 's/@/\\@/g' \
> "$UZBL_FIFO"
}
diff --git a/examples/data/scripts/go_input.js b/examples/data/scripts/go_input.js
index 557671f..fedbd90 100644
--- a/examples/data/scripts/go_input.js
+++ b/examples/data/scripts/go_input.js
@@ -18,7 +18,7 @@ function gi() {
else {
el.focus();
}
- return "XXXEMIT_FORM_ACTIVEXXX";
+ return "XXXFORM_ACTIVEXXX";
}
}
}
diff --git a/examples/data/scripts/go_input.sh b/examples/data/scripts/go_input.sh
index 9797788..973ae4f 100755
--- a/examples/data/scripts/go_input.sh
+++ b/examples/data/scripts/go_input.sh
@@ -1,7 +1,7 @@
#!/bin/sh
case "$( echo "script @scripts_dir/go_input.js" | socat - "unix-connect:$UZBL_SOCKET" )" in
- *XXXEMIT_FORM_ACTIVEXXX*)
- echo "event FORM_ACTIVE" > "$UZBL_FIFO"
+ *XXXFORM_ACTIVEXXX*)
+ echo 'event KEYCMD_CLEAR' > "$UZBL_FIFO"
;;
esac
diff --git a/examples/data/scripts/load_cookies.sh b/examples/data/scripts/load_cookies.sh
index c7fcc58..380301e 100755
--- a/examples/data/scripts/load_cookies.sh
+++ b/examples/data/scripts/load_cookies.sh
@@ -13,9 +13,11 @@ BEGIN {
scheme["FALSE"] = "http";
}
$0 ~ /^#HttpOnly_/ {
+ gsub(/@/, "\\@")
printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", substr($1,length("#HttpOnly_"),length($1)), $3, $6, $7, scheme[$4], $5)
}
$0 !~ /^#/ {
+ gsub(/@/, "\\@")
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/session.sh b/examples/data/scripts/session.sh
index 4e7bfd1..96db4f8 100755
--- a/examples/data/scripts/session.sh
+++ b/examples/data/scripts/session.sh
@@ -33,7 +33,6 @@ UZBL="uzbl-browser -c \"$UZBL_CONFIG_FILE\"" # add custom flags and whatever her
scriptfile="$( readlink -f "$0" )" # this script
act="$1"
-shift
if [ -z "$act" ]; then
[ -f "$UZBL_SESSION_FILE" ] && act="launch" || act="endsession"