aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/config/config10
-rwxr-xr-xexamples/data/scripts/download.sh46
-rw-r--r--examples/data/scripts/follow.js416
-rwxr-xr-xexamples/data/scripts/follow.sh28
-rwxr-xr-xexamples/data/scripts/go_input.sh6
-rwxr-xr-xexamples/data/scripts/history.sh6
-rwxr-xr-xexamples/data/scripts/insert_bookmark.sh11
-rwxr-xr-xexamples/data/scripts/instance-select-wmii.sh25
-rwxr-xr-xexamples/data/scripts/load_cookies.sh17
-rwxr-xr-xexamples/data/scripts/load_url_from_bookmarks.sh10
-rwxr-xr-xexamples/data/scripts/load_url_from_history.sh13
-rwxr-xr-xexamples/data/scripts/session.sh28
-rw-r--r--examples/data/scripts/util/dmenu.sh2
-rw-r--r--examples/data/scripts/util/uzbl-dir.sh18
-rw-r--r--examples/data/scripts/util/uzbl-window.sh16
-rwxr-xr-xexamples/data/scripts/uzbl-tabbed7
-rw-r--r--examples/data/style.css38
17 files changed, 359 insertions, 338 deletions
diff --git a/examples/config/config b/examples/config/config
index ab690e0..6de0b59 100644
--- a/examples/config/config
+++ b/examples/config/config
@@ -72,6 +72,7 @@ set download_handler = sync_spawn @scripts_dir/download.sh
# add some javascript to the page for other 'js' and 'script' commands to access later.
@on_event LOAD_COMMIT js uzbl = {};
@on_event LOAD_COMMIT script @scripts_dir/formfiller.js
+@on_event LOAD_COMMIT script @scripts_dir/follow.js
# Userscripts/per-site-settings. See the script and the example configuration for details
#@on_event LOAD_COMMIT spawn @scripts_dir/per-site-settings.py @data_home/uzbl/per-site-settings
@@ -93,6 +94,9 @@ set download_handler = sync_spawn @scripts_dir/download.sh
# === Behaviour and appearance ===============================================
+# Custom CSS can be defined here, including link follower hint styles
+set stylesheet_uri = file://@data_home/uzbl/style.css
+
set show_status = 1
set status_top = 0
set status_background = #303030
@@ -263,6 +267,9 @@ set ebind = @mode_bind global,-insert
@cbind n = search
@cbind N = search_reverse
+# Print pages to a printer
+@cbind  <Ctrl>p = hardcopy
+
# Web searching binds
@cbind gg<Google:>_ = uri http://www.google.com/search?q=\@<encodeURIComponent(%r)>\@
@cbind ddg<DuckDuckGo:>_ = uri http://duckduckgo.com/?q=%s
@@ -327,7 +334,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* = spawn @scripts_dir/follow.sh "%s"
+@cbind fl* = spawn @scripts_dir/follow.sh \@< uzbl.follow("\@follow_hint_keys", "%s", 0) >\@
+@cbind Fl* = spawn @scripts_dir/follow.sh \@< uzbl.follow("\@follow_hint_keys", "%s", 1) >\@
@cbind gi = spawn @scripts_dir/go_input.sh
# Form filler binds
diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh
index c410ad2..fe566ed 100755
--- a/examples/data/scripts/download.sh
+++ b/examples/data/scripts/download.sh
@@ -1,25 +1,55 @@
#!/bin/sh
-#
# 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.
-. $UZBL_UTIL_DIR/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
# the URL that is being downloaded
-uri=$1
+uri="$1"
+shift
+
+safe_uri="$( echo "$uri" | sed -e 's/\W/-/g' )"
# a filename suggested by the server or based on the URL
-suggested_filename=${2:-$(echo "$uri" | sed 's/\W/-/g')}
+suggested_filename="${1:-$safe_uri}"
+shift
# the mimetype of the file being downloaded
-content_type=$3
+content_type="$1"
+shift
# 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
+total_size="$1"
+shift
+
+case "$suggested_filename" in
+ # example: save torrents to a separate directory
+ #*.torrent)
+ # path="$UZBL_DOWNLOAD_DIR/torrents/$suggested_filename"
+ # ;;
+ # Default case
+ *)
+ path="$UZBL_DOWNLOAD_DIR/$suggested_filename"
+ ;;
+esac
+
+# Do nothing if we don't want to save the file
+[ -z "$path" ] && exit 0
+
+# Check if the file exists
+if [ ! -e "$path" ]; then
+ echo "$path"
+ exit 0
+fi
+
+# Try to make a unique filename
+count=1
+while [ -e "$path.$count" ]; do
+ count=$(( $count + 1 ))
+done
-# just save the file to the default directory with the suggested name
-echo $UZBL_DOWNLOAD_DIR/$suggested_filename
+echo "$path.$count"
diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js
index d995696..536256b 100644
--- a/examples/data/scripts/follow.js
+++ b/examples/data/scripts/follow.js
@@ -1,219 +1,192 @@
/* This is the basic linkfollowing script.
- * Its pretty stable, and you configure which keys to use for hinting
*
- * TODO: Some pages mess around a lot with the zIndex which
- * lets some hints in the background.
- * TODO: Some positions are not calculated correctly (mostly
- * because of uber-fancy-designed-webpages. Basic HTML and CSS
- * works good
- * TODO: Still some links can't be followed/unexpected things
- * happen. Blame some freaky webdesigners ;)
+ * TODO:
+ * Some pages mess around a lot with the zIndex which
+ * lets some hints in the background.
+ * Some positions are not calculated correctly (mostly
+ * because of uber-fancy-designed-webpages. Basic HTML and CSS
+ * works good
+ * Still some links can't be followed/unexpected things
+ * happen. Blame some freaky webdesigners ;)
*/
-//Just some shortcuts and globals
-var uzblid = 'uzbl_link_hint';
-var uzbldivid = uzblid + '_div_container';
-var doc = document;
-var win = window;
-var links = document.links;
-var forms = document.forms;
-//Make onlick-links "clickable"
-try {
- HTMLElement.prototype.click = function() {
- if (typeof this.onclick == 'function') {
- this.onclick({
- type: 'click'
- });
- }
- };
-} catch(e) {}
-//Catch the ESC keypress to stop linkfollowing
-function keyPressHandler(e) {
- var kC = window.event ? event.keyCode: e.keyCode;
- var Esc = window.event ? 27 : e.DOM_VK_ESCAPE;
- if (kC == Esc) {
- removeAllHints();
- }
+// Globals
+uzbldivid = 'uzbl_link_hints';
+
+uzbl.follow = function() {
+ // Export
+ charset = arguments[0];
+ newwindow = arguments[2];
+
+ var keypress = arguments[1];
+ return arguments.callee.followLinks(keypress);
+}
+
+uzbl.follow.isFrame = function(el) {
+ return (el.tagName == "FRAME" || el.tagName == "IFRAME");
+}
+
+// find the document that the given element belongs to
+uzbl.follow.getDocument = function(el) {
+ if (this.isFrame(el))
+ return el.contentDocument;
+
+ var doc = el;
+ while (doc.parentNode !== null)
+ doc = doc.parentNode;
+ return doc;
+}
+
+// find all documents in the display, searching frames recursively
+uzbl.follow.documents = function() {
+ return this.windows().map(function(w) { return w.document; }).filter(function(d) { return d != null; });
+}
+
+// find all windows in the display, searching for frames recursively
+uzbl.follow.windows = function(w) {
+  w = (typeof w == 'undefined') ? window.top : w;
+
+ var wins = [w];
+ var frames = w.frames;
+ for(var i = 0; i < frames.length; i++)
+ wins = wins.concat(uzbl.follow.windows(frames[i]));
+ return wins;
+}
+
+// search all frames for elements matching the given CSS selector
+uzbl.follow.query = function(selector) {
+ var res = [];
+ this.documents().forEach(function (doc) {
+ var set = doc.body.querySelectorAll(selector);
+ // convert the NodeList to an Array
+ set = Array.prototype.slice.call(set);
+ res = res.concat(set);
+ });
+ return res;
}
-//Calculate element position to draw the hint
-//Pretty accurate but on fails in some very fancy cases
-function elementPosition(el) {
- var up = el.offsetTop;
- var left = el.offsetLeft;
- var width = el.offsetWidth;
+
+// Calculate element position to draw the hint
+uzbl.follow.elementPosition = function(el) {
+ // el.getBoundingClientRect is another way to do this, but when a link is
+ // line-wrapped we want our hint at the left end of the link, not its
+ // bounding rectangle
+ var up = el.offsetTop;
+ var left = el.offsetLeft;
+ var width = el.offsetWidth;
var height = el.offsetHeight;
+
while (el.offsetParent) {
el = el.offsetParent;
up += el.offsetTop;
left += el.offsetLeft;
}
+
return [up, left, width, height];
}
-//Calculate if an element is visible
-function isVisible(el) {
- if (el == doc) {
- return true;
- }
- if (!el) {
- return false;
- }
- if (!el.parentNode) {
- return false;
- }
- if (el.style) {
- if (el.style.display == 'none') {
- return false;
- }
- if (el.style.visibility == 'hidden') {
- return false;
- }
- }
- return isVisible(el.parentNode);
-}
-//Calculate if an element is on the viewport.
-function elementInViewport(el) {
- offset = elementPosition(el);
- var up = offset[0];
- var left = offset[1];
- var width = offset[2];
+
+// Calculate if an element is on the viewport.
+uzbl.follow.elementInViewport = function(el) {
+ offset = uzbl.follow.elementPosition(el);
+ var up = offset[0];
+ var left = offset[1];
+ var width = offset[2];
var height = offset[3];
- return up < window.pageYOffset + window.innerHeight && left < window.pageXOffset + window.innerWidth && (up + height) > window.pageYOffset && (left + width) > window.pageXOffset;
+ return up < window.pageYOffset + window.innerHeight &&
+ left < window.pageXOffset + window.innerWidth &&
+ (up + height) > window.pageYOffset &&
+ (left + width) > window.pageXOffset;
}
-//Removes all hints/leftovers that might be generated
-//by this script.
-function removeAllHints() {
+
+// Removes all hints/leftovers that might be generated
+// by this script.
+uzbl.follow.removeAllHints = function(doc) {
var elements = doc.getElementById(uzbldivid);
- if (elements) {
- elements.parentNode.removeChild(elements);
- }
+ if (elements) elements.parentNode.removeChild(elements);
}
-//Generate a hint for an element with the given label
-//Here you can play around with the style of the hints!
-function generateHint(el, label) {
- var pos = elementPosition(el);
- var hint = doc.createElement('div');
- hint.setAttribute('name', uzblid);
+
+// Generate a hint for an element with the given label
+// Here you can play around with the style of the hints!
+uzbl.follow.generateHint = function(doc, el, label, top, left) {
+ var hint = doc.createElement('span');
hint.innerText = label;
- hint.style.display = 'inline';
- hint.style.backgroundColor = '#B9FF00';
- hint.style.border = '2px solid #4A6600';
- hint.style.color = 'black';
- hint.style.fontSize = '9px';
- hint.style.fontWeight = 'bold';
- hint.style.lineHeight = '9px';
- hint.style.margin = '0px';
- hint.style.width = 'auto'; // fix broken rendering on w3schools.com
- hint.style.padding = '1px';
hint.style.position = 'absolute';
- hint.style.zIndex = '1000';
- // hint.style.textTransform = 'uppercase';
- hint.style.left = pos[1] + 'px';
- hint.style.top = pos[0] + 'px';
- // var img = el.getElementsByTagName('img');
- // if (img.length > 0) {
- // hint.style.top = pos[1] + img[0].height / 2 - 6 + 'px';
- // }
- hint.style.textDecoration = 'none';
- // hint.style.webkitBorderRadius = '6px'; // slow
- // Play around with this, pretty funny things to do :)
- // hint.style.webkitTransform = 'scale(1) rotate(0deg) translate(-6px,-5px)';
+ hint.style.top = top + 'px';
+ hint.style.left = left + 'px';
return hint;
}
-// Here we choose what to do with an element that the user has selected.
-// Form elements get selected and/or focussed, and links and buttons are
-// clicked. This function returns "XXXRESET_MODEXXX" to indicate that uzbl
-// should be reset to command mode with an empty keycmd, or
-// "XXX_EMIT_FORM_ACTIVEXXX" to indicate that uzbl should be set to insert mode.
-function clickElem(item) {
- removeAllHints();
- if (item) {
- var name = item.tagName;
- if (name == 'BUTTON') {
- item.click();
- return "XXXRESET_MODEXXX";
- } else if (name == 'INPUT') {
- var type = item.type.toUpperCase();
- 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') {
+// 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)
+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') {
item.focus();
item.select();
return "XXXEMIT_FORM_ACTIVEXXX";
- } else {
- item.click();
- window.location = item.href;
- return "XXXRESET_MODEXXX";
}
+ // otherwise fall through to a simulated mouseclick.
+ } else if (name == 'TEXTAREA' || name == 'SELECT') {
+ item.focus();
+ item.select();
+ return "XXXEMIT_FORM_ACTIVEXXX";
}
+
+ // simulate a mouseclick to activate the element
+ var mouseEvent = document.createEvent("MouseEvent");
+ mouseEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
+ item.dispatchEvent(mouseEvent);
+ return "XXXRESET_MODEXXX";
}
-//Returns a list of all links (in this version
-//just the elements itself, but in other versions, we
-//add the label here.
-function addLinks() {
- res = [[], []];
- for (var l = 0; l < links.length; l++) {
- var li = links[l];
- if (isVisible(li) && elementInViewport(li)) {
- res[0].push(li);
- }
- }
- return res;
-}
-//Same as above, just for the form elements
-function addFormElems() {
- res = [[], []];
- 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', 'BUTTON'].indexOf(el.tagName) + 1 && isVisible(el) && elementInViewport(el)) {
- res[0].push(el);
- }
- }
- }
- return res;
-}
-//Draw all hints for all elements passed. "len" is for
-//the number of chars we should use to avoid collisions
-function reDrawHints(elems, chars) {
- removeAllHints();
- var hintdiv = doc.createElement('div');
- hintdiv.setAttribute('id', uzbldivid);
- for (var i = 0; i < elems[0].length; i++) {
- if (elems[0][i]) {
- var label = elems[1][i].substring(chars);
- var h = generateHint(elems[0][i], label);
- hintdiv.appendChild(h);
- }
- }
- if (document.body) {
- document.body.appendChild(hintdiv);
- }
+
+// 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) });
+ // 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);
+
+ this.documents().forEach(function(doc) {
+ uzbl.follow.removeAllHints(doc);
+ if (!doc.body) return;
+ doc.hintdiv = doc.createElement('div');
+ doc.hintdiv.id = uzbldivid;
+ if(newwindow) doc.hintdiv.className = "new-window";
+ doc.body.appendChild(doc.hintdiv);
+ });
+
+ 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);
+ });
}
+
// pass: number of keys
// returns: key length
-function labelLength(n) {
+uzbl.follow.labelLength = function(n) {
var oldn = n;
var keylen = 0;
- if(n < 2) {
- return 1;
- }
- n -= 1; // our highest key will be n-1
+ if(n < 2) return 1;
+ n -= 1; // Our highest key will be n-1
while(n) {
keylen += 1;
n = Math.floor(n / charset.length);
}
return keylen;
}
+
// pass: number
// returns: label
-function intToLabel(n) {
+uzbl.follow.intToLabel = function(n) {
var label = '';
do {
label = charset.charAt(n % charset.length) + label;
@@ -221,55 +194,68 @@ function intToLabel(n) {
} while(n);
return label;
}
+
// pass: label
// returns: number
-function labelToInt(label) {
+uzbl.follow.labelToInt = function(label) {
var n = 0;
- var i;
- for(i = 0; i < label.length; ++i) {
+ for(var i = 0; i < label.length; ++i) {
n *= charset.length;
n += charset.indexOf(label[i]);
}
return n;
}
-//Put it all together
-function followLinks(follow) {
- // if(follow.charAt(0) == 'l') {
- // follow = follow.substr(1);
- // charset = 'thsnlrcgfdbmwvz-/';
- // }
+
+// Put it all together
+uzbl.follow.followLinks = function(follow) {
var s = follow.split('');
- var linknr = labelToInt(follow);
- if (document.body) document.body.setAttribute('onkeyup', 'keyPressHandler(event)');
- var linkelems = addLinks();
- var formelems = addFormElems();
- var elems = [linkelems[0].concat(formelems[0]), linkelems[1].concat(formelems[1])];
- var len = labelLength(elems[0].length);
- var oldDiv = doc.getElementById(uzbldivid);
- var leftover = [[], []];
- if (s.length == len && linknr < elems[0].length && linknr >= 0) {
- return clickElem(elems[0][linknr]);
- } else {
- for (var j = 0; j < elems[0].length; j++) {
- var b = true;
- var label = 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[0].push(elems[0][j]);
- leftover[1].push(label);
- }
+ var linknr = this.labelToInt(follow);
+
+ var followable = 'a, area, textarea, select, input:not([type=hidden]), button';
+ 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)
+ var res = this.query(uri);
+ else
+ var res = this.query(followable);
+
+ var elems = res.filter(uzbl.follow.elementInViewport);
+ var len = this.labelLength(elems.length);
+
+ if (s.length == len && linknr < elems.length && linknr >= 0) {
+ // an element has been selected!
+ var el = elems[linknr];
+
+ // clear all of our hints
+ this.documents().forEach(uzbl.follow.removeAllHints);
+
+ 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"
}
- reDrawHints(leftover, s.length);
+
+ // we're just going to click the element
+ return this.clickElem(el);
}
-}
-//Parse input: first argument is follow keys, second is user input.
-var args = '%s'.split(' ');
-var charset = args[0];
-followLinks(args[1]);
+ 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]);
+ }
+
+ this.reDrawHints(leftover, s.length);
+}
diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh
index d7fe117..014793e 100755
--- a/examples/data/scripts/follow.sh
+++ b/examples/data/scripts/follow.sh
@@ -1,21 +1,13 @@
#!/bin/sh
+# This scripts acts on the return value of followLinks in follow.js
-# This script is just a wrapper around follow.js that lets us change uzbl's mode
-# after a link is selected.
-
-# 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
- echo 'script @scripts_dir/follow.js "@{follow_hint_keys} '$1'"' > "$UZBL_FIFO"
- exit
-fi
-
-result=$(echo 'script @scripts_dir/follow.js "@{follow_hint_keys} '$1'"' | socat - unix-connect:"$UZBL_SOCKET")
-case $result in
- *XXXEMIT_FORM_ACTIVEXXX*)
- # a form element was selected
- echo 'event FORM_ACTIVE' > "$UZBL_FIFO" ;;
- *XXXRESET_MODEXXX*)
- # a link was selected, reset uzbl's input mode
- printf 'set mode=\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO" ;;
+case "$1" in
+ XXXEMIT_FORM_ACTIVEXXX)
+ # a form element was selected
+ printf 'event FORM_ACTIVE\nevent 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"
+ ;;
esac
diff --git a/examples/data/scripts/go_input.sh b/examples/data/scripts/go_input.sh
index ace0e79..9797788 100755
--- a/examples/data/scripts/go_input.sh
+++ b/examples/data/scripts/go_input.sh
@@ -1,5 +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" ;;
+case "$( echo "script @scripts_dir/go_input.js" | socat - "unix-connect:$UZBL_SOCKET" )" in
+ *XXXEMIT_FORM_ACTIVEXXX*)
+ echo "event FORM_ACTIVE" > "$UZBL_FIFO"
+ ;;
esac
diff --git a/examples/data/scripts/history.sh b/examples/data/scripts/history.sh
index 266d65d..0709b5e 100755
--- a/examples/data/scripts/history.sh
+++ b/examples/data/scripts/history.sh
@@ -1,7 +1,7 @@
#!/bin/sh
-. $UZBL_UTIL_DIR/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
-[ -w "$UZBL_HISTORY_FILE" ] || [ ! -a "$UZBL_HISTORY_FILE" ] || exit 1
+>> "$UZBL_HISTORY_FILE" || exit 1
-echo $(date +'%Y-%m-%d %H:%M:%S')" $UZBL_URI $UZBL_TITLE" >> $UZBL_HISTORY_FILE
+echo "$( date +'%Y-%m-%d %H:%M:%S' ) $UZBL_URI $UZBL_TITLE" >> "$UZBL_HISTORY_FILE"
diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh
index f67e67a..f310e49 100755
--- a/examples/data/scripts/insert_bookmark.sh
+++ b/examples/data/scripts/insert_bookmark.sh
@@ -1,15 +1,14 @@
#!/bin/sh
-. "$UZBL_UTIL_DIR"/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
-[ -d "$UZBL_DATA_DIR" ] || exit 1
-[ -w "$UZBL_BOOKMARKS_FILE" ] || [ ! -a "$UZBL_BOOKMARKS_FILE" ] || exit 1
+>> "$UZBL_BOOKMARKS_FILE" || exit 1
which zenity >/dev/null 2>&1 || exit 2
-tags=$(zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URI:")
-exitstatus=$?
-[ $exitstatus -eq 0 ] || exit $exitstatus
+tags="$( zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URI:" )"
+exitstatus="$?"
+[ "$exitstatus" -eq 0 ] || exit "$exitstatus"
# TODO: check if already exists, if so, and tags are different: ask if you want to replace tags
echo "$UZBL_URI $tags" >> "$UZBL_BOOKMARKS_FILE"
diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh
index 19d04e8..b2aadbb 100755
--- a/examples/data/scripts/instance-select-wmii.sh
+++ b/examples/data/scripts/instance-select-wmii.sh
@@ -1,6 +1,5 @@
#!/bin/sh
-
# This script allows you to focus another uzbl window
# It considers all uzbl windows in the current tag
# you can select one from a list, or go to the next/previous one
@@ -13,30 +12,30 @@
DMENU_SCHEME="wmii"
-. $UZBL_UTIL_DIR/dmenu.sh
+. "$UZBL_UTIL_DIR/dmenu.sh"
case "$1" in
- "list" )
- list=
+ "list")
+ list=""
# get window id's of uzbl clients. we could also get the label in one shot but it's pretty tricky
- for i in $(wmiir read /tag/sel/index | grep uzbl |cut -d ' ' -f2); do
- label=$(wmiir read /client/$i/label)
+ for i in $( wmiir read /tag/sel/index | grep uzbl | cut -d ' ' -f 2 ); do
+ label="$( wmiir read /client/$i/label )"
list="$list$i : $label\n"
done
- window=$(printf "$list\n" | $DMENU | cut -d ' ' -f1)
+ window="$( echo "$list" | $DMENU | cut -d ' ' -f 1 )"
wmiir xwrite /tag/sel/ctl "select client $window"
;;
- "next" )
- current=$(wmiir read /client/sel/ctl | head -n 1)
+ "next")
+ current="$( wmiir read /client/sel/ctl | head -n 1 )"
# find the next uzbl window and focus it
- next=$(wmiir read /tag/sel/index | grep -A 10000 " $current " | grep -m 1 uzbl | cut -d ' ' -f2)
+ next="$( wmiir read /tag/sel/index | grep -A 10000 " $current " | grep -m 1 uzbl | cut -d ' ' -f 2 )"
if [ -n "$next" ]; then
wmiir xwrite /tag/sel/ctl "select client $next"
fi
;;
- "prev" )
- current=$(wmiir read /client/sel/ctl | head -n 1)
- prev=$(wmiir read /tag/sel/index | grep -B 10000 " $current " | tac | grep -m 1 uzbl | cut -d ' ' -f2)
+ "prev")
+ current="$( wmiir read /client/sel/ctl | head -n 1 )"
+ prev="$( wmiir read /tag/sel/index | grep -B 10000 " $current " | tac | grep -m 1 uzbl | cut -d ' ' -f 2 )"
if [ -n "$prev" ]; then
wmiir xwrite /tag/sel/ctl "select client $prev"
fi
diff --git a/examples/data/scripts/load_cookies.sh b/examples/data/scripts/load_cookies.sh
index 17ec2ad..c7fcc58 100755
--- a/examples/data/scripts/load_cookies.sh
+++ b/examples/data/scripts/load_cookies.sh
@@ -1,20 +1,21 @@
#!/bin/sh
-if [ "$1" != "" ]; then
- cookie_file=$1
+if [ -n "$1" ]; then
+ cookie_file="$1"
+ shift
else
- cookie_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/cookies.txt
+ cookie_file="${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/cookies.txt"
fi
awk -F \\t '
BEGIN {
- scheme["TRUE"] = "https";
- scheme["FALSE"] = "http";
+ 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)
+ 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)
+ printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", $1, $3, $6, $7, scheme[$4], $5)
}
-' $cookie_file
+' "$cookie_file"
diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh
index a5d9586..a03db4b 100755
--- a/examples/data/scripts/load_url_from_bookmarks.sh
+++ b/examples/data/scripts/load_url_from_bookmarks.sh
@@ -5,18 +5,18 @@
DMENU_SCHEME="bookmarks"
DMENU_OPTIONS="xmms vertical resize"
-. "$UZBL_UTIL_DIR"/dmenu.sh
-. "$UZBL_UTIL_DIR"/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/dmenu.sh"
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
[ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1
if [ -z "$DMENU_HAS_VERTICAL" ]; then
# because they are all after each other, just show the url, not their tags.
- goto=$(awk '{print $1}' "$UZBL_BOOKMARKS_FILE" | $DMENU)
+ goto="$( awk '{ print $1 }' "$UZBL_BOOKMARKS_FILE" | $DMENU )"
else
# show tags as well
- goto=$($DMENU < "$UZBL_BOOKMARKS_FILE" | awk '{print $1}')
+ goto="$( $DMENU < "$UZBL_BOOKMARKS_FILE" | cut -d ' ' -f 1 )"
fi
[ -n "$goto" ] && echo "uri $goto" > "$UZBL_FIFO"
-#[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:"$UZBL_SOCKET"
+#[ -n "$goto" ] && echo "uri $goto" | socat - "unix-connect:$UZBL_SOCKET"
diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh
index 59ad492..24bfdce 100755
--- a/examples/data/scripts/load_url_from_history.sh
+++ b/examples/data/scripts/load_url_from_history.sh
@@ -3,21 +3,20 @@
DMENU_SCHEME="history"
DMENU_OPTIONS="xmms vertical resize"
-. "$UZBL_UTIL_DIR"/dmenu.sh
-. "$UZBL_UTIL_DIR"/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/dmenu.sh"
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
[ -r "$UZBL_HISTORY_FILE" ] || exit 1
# choose from all entries, sorted and uniqued
-# goto=$(awk '{print $3}' $history_file | sort -u | dmenu -i)
if [ -z "$DMENU_HAS_VERTICAL" ]; then
- current=$(tail -n 1 "$UZBL_HISTORY_FILE" | awk '{print $3}');
- goto=$( (echo $current; awk '{print $3}' "$UZBL_HISTORY_FILE" | grep -v "^$current\$" | sort -u) | $DMENU)
+ current="$( tail -n 1 "$UZBL_HISTORY_FILE" | cut -d ' ' -f 3 )"
+ goto="$( ( echo "$current"; awk '{ print $3 }' "$UZBL_HISTORY_FILE" | grep -v "^$current\$" | sort -u ) | $DMENU )"
else
# choose an item in reverse order, showing also the date and page titles
# pick the last field from the first 3 fields. this way you can pick a url (prefixed with date & time) or type just a new url.
- goto=$(tac "$UZBL_HISTORY_FILE" | $DMENU | cut -d ' ' -f -3 | awk '{print $NF}')
+ goto="$( tac "$UZBL_HISTORY_FILE" | $DMENU | cut -d ' ' -f -3 | awk '{ print $NF }' )"
fi
[ -n "$goto" ] && echo "uri $goto" > "$UZBL_FIFO"
-#[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:"$UZBL_SOCKET"
+#[ -n "$goto" ] && echo "uri $goto" | socat - "unix-connect:$UZBL_SOCKET"
diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh
index ee09cf2..4e7bfd1 100755
--- a/examples/data/scripts/session.sh
+++ b/examples/data/scripts/session.sh
@@ -18,28 +18,30 @@
if [ -z "$UZBL_UTIL_DIR" ]; then
# we're being run standalone, we have to figure out where $UZBL_UTIL_DIR is
# using the same logic as uzbl-browser does.
- UZBL_UTIL_DIR=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/scripts/util
+ UZBL_UTIL_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/scripts/util"
if ! [ -d "$UZBL_UTIL_DIR" ]; then
- PREFIX=$(grep '^PREFIX' "$(which uzbl-browser)" | sed 's/.*=//')
- UZBL_UTIL_DIR=$PREFIX/share/uzbl/examples/data/scripts/util
+ PREFIX="$( grep '^PREFIX' "$( which uzbl-browser )" | sed -e 's/.*=//' )"
+ UZBL_UTIL_DIR="$PREFIX/share/uzbl/examples/data/scripts/util"
fi
fi
-. "$UZBL_UTIL_DIR"/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
+
[ -d "$UZBL_DATA_DIR" ] || exit 1
-UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here.
+UZBL="uzbl-browser -c \"$UZBL_CONFIG_FILE\"" # add custom flags and whatever here.
-scriptfile=$(readlink -f $0) # this script
+scriptfile="$( readlink -f "$0" )" # this script
act="$1"
+shift
if [ -z "$act" ]; then
[ -f "$UZBL_SESSION_FILE" ] && act="launch" || act="endsession"
fi
case $act in
- "launch" )
- urls=$(cat "$UZBL_SESSION_FILE")
+ "launch")
+ urls="$( cat "$UZBL_SESSION_FILE" )"
if [ -z "$urls" ]; then
$UZBL
else
@@ -50,17 +52,17 @@ case $act in
fi
;;
- "endinstance" )
+ "endinstance")
if [ -z "$UZBL_FIFO" ]; then
echo "session manager: endinstance must be called from uzbl"
exit 1
fi
[ "$UZBL_URI" != "(null)" ] && echo "$UZBL_URI" >> "$UZBL_SESSION_FILE"
- echo exit > "$UZBL_FIFO"
+ echo "exit" > "$UZBL_FIFO"
;;
- "endsession" )
- for fifo in "$UZBL_FIFO_DIR"/uzbl_fifo_*; do
+ "endsession")
+ for fifo in "$UZBL_FIFO_DIR/uzbl_fifo_*"; do
if [ "$fifo" != "$UZBL_FIFO" ]; then
echo "spawn $scriptfile endinstance" > "$fifo"
fi
@@ -68,7 +70,7 @@ case $act in
[ -z "$UZBL_FIFO" ] || echo "spawn $scriptfile endinstance" > "$UZBL_FIFO"
;;
- * )
+ *)
echo "session manager: bad action"
echo "Usage: $scriptfile [COMMAND] where commands are:"
echo " launch - Restore a saved session or start a new one"
diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh
index 354d7d1..f0d1651 100644
--- a/examples/data/scripts/util/dmenu.sh
+++ b/examples/data/scripts/util/dmenu.sh
@@ -98,7 +98,7 @@ if dmenu --help 2>&1 | grep -q '\[-l <\?lines>\?\]'; then
fi
# Detect placement patch
-if dmenu --help 2>&1 | grep -q '\[-x <xoffset>\]'; then
+if dmenu --help 2>&1 | grep -q '\[-x <\?xoffset>\?\]'; then
DMENU_PLACE_X="-x"
DMENU_PLACE_Y="-y"
DMENU_PLACE_WIDTH="-w"
diff --git a/examples/data/scripts/util/uzbl-dir.sh b/examples/data/scripts/util/uzbl-dir.sh
index bb56954..3d28151 100644
--- a/examples/data/scripts/util/uzbl-dir.sh
+++ b/examples/data/scripts/util/uzbl-dir.sh
@@ -2,18 +2,18 @@
# Common directories and files used in scripts
# Common things first
-UZBL_DATA_DIR=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl
-UZBL_CONFIG_DIR=${XDG_CONFIG_DIR:-$HOME/.config}/uzbl
+UZBL_DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/uzbl"
+UZBL_CONFIG_DIR="${XDG_CONFIG_DIR:-$HOME/.config}/uzbl"
UZBL_FIFO_DIR=/tmp
UZBL_SOCKET_DIR=/tmp
# Directories
-UZBL_DOWNLOAD_DIR=${XDG_DOWNLOAD_DIR:-$HOME}
-UZBL_FORMS_DIR=$UZBL_DATA_DIR/dforms
+UZBL_DOWNLOAD_DIR="${XDG_DOWNLOAD_DIR:-$HOME}"
+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_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"
diff --git a/examples/data/scripts/util/uzbl-window.sh b/examples/data/scripts/util/uzbl-window.sh
index a7e92eb..4b96372 100644
--- a/examples/data/scripts/util/uzbl-window.sh
+++ b/examples/data/scripts/util/uzbl-window.sh
@@ -1,11 +1,11 @@
#!/bin/sh
# uzbl window detection
-UZBL_WIN_POS=$(xwininfo -id $UZBL_XID | \
- sed -ne 's/Corners:[ ]*[+-]\([0-9]*\)[+-]\([0-9]*\).*$/\1 \2/p')
-UZBL_WIN_SIZE=$(xwininfo -id $UZBL_XID | \
- sed -ne 's/-geometry[ ]*\([0-9]*\)x\([0-9]*\).*$/\1 \2/p')
-UZBL_WIN_POS_X=$(echo $UZBL_WIN_POS | cut -d\ -f1)
-UZBL_WIN_POS_Y=$(echo $UZBL_WIN_POS | cut -d\ -f2)
-UZBL_WIN_WIDTH=$(echo $UZBL_WIN_SIZE | cut -d\ -f1)
-UZBL_WIN_HEIGHT=$(echo $UZBL_WIN_SIZE | cut -d\ -f2)
+UZBL_WIN_POS="$( xwininfo -id "$UZBL_XID" | \
+ sed -n -e '[ ]*s/Corners:[ ]*[+-]\([0-9]*\)[+-]\([0-9]*\).*$/\1 \2/p' )"
+UZBL_WIN_SIZE="$( xwininfo -id "$UZBL_XID" | \
+ sed -n -e '[ ]*s/-geometry[ ]*\([0-9]*\)x\([0-9]*\).*$/\1 \2/p' )"
+UZBL_WIN_POS_X="$( echo "$UZBL_WIN_POS" | cut -d ' ' -f 1 )"
+UZBL_WIN_POS_Y="$( echo "$UZBL_WIN_POS" | cut -d ' ' -f 2 )"
+UZBL_WIN_WIDTH="$( echo "$UZBL_WIN_SIZE" | cut -d ' ' -f 1 )"
+UZBL_WIN_HEIGHT="$( echo "$UZBL_WIN_SIZE" | cut -d ' ' -f 2 )"
diff --git a/examples/data/scripts/uzbl-tabbed b/examples/data/scripts/uzbl-tabbed
index 13e4e44..0c347b5 100755
--- a/examples/data/scripts/uzbl-tabbed
+++ b/examples/data/scripts/uzbl-tabbed
@@ -482,8 +482,11 @@ class UzblInstance:
self.parent.update_gtk_tab_pos()
elif var == "status_background":
if config['status_background'].strip():
- col = gtk.gdk.color_parse(config['status_background'])
- self.parent.ebox.modify_bg(gtk.STATE_NORMAL, col)
+ try:
+ col = gtk.gdk.color_parse(config['status_background'])
+ self.parent.ebox.modify_bg(gtk.STATE_NORMAL, col)
+ except ValueError:
+ pass # got an invalid colour, just ignore it
elif var == "tab_titles" or var == "tab_indexes":
for tab in self.parent.notebook:
self.parent.tabs[tab].title_changed(True)
diff --git a/examples/data/style.css b/examples/data/style.css
index f9b111e..ff055d1 100644
--- a/examples/data/style.css
+++ b/examples/data/style.css
@@ -1,25 +1,25 @@
-.uzbl_highlight { background-color: yellow;}
-.uzbl_h_first { background-color: lightgreen;}
+#uzbl_link_hints > span {
+ z-index: 1000 !important;
-.uzbl_follow { border-style: dotted;
- border-width: thin;
+ background-color: #aaff00 !important;
+ border: 2px solid #556600 !important;
+ margin: 0 !important;
+ padding: 1px !important;
+
+ color: black !important;
+ font-size: 9px !important;
+ line-height: 9px !important;
+ font-weight: bold !important;
+ font-variant: normal !important;
+ text-decoration: none !important;
+
+ -webkit-transform: translate(-5px,-5px);
+ /* opacity: 0.7; */
}
-#uzbl_hint > div {
- display: inline;
- border: 2px solid #4a6600;
- background-color: #b9ff00;
- color: black;
- font-size: 9px;
- font-weight: bold;
- line-height: 9px;
- margin: 0px;
- padding: 0px;
- position: absolute;
- z-index: 1000;
- -webkit-border-radius: 6px;
- text-decoration: none;
- -wekit-transform: scale(1) rotate(0deg) translate(-6px,-5px);
+/* we can have different colours for different types of hints! */
+#uzbl_link_hints.new-window > span {
+ background-color: #ffff00 !important;
}
/* vim:set et ts=4: */