From 198afaca6d39a5fa2e9927ad6a297fe166a0b5b1 Mon Sep 17 00:00:00 2001 From: cy Date: Mon, 28 Dec 2009 21:17:10 +0200 Subject: add link following script with configurable keys --- examples/data/uzbl/scripts/follow.js | 256 +++++++++++++++++++++++++++++++++++ 1 file changed, 256 insertions(+) create mode 100644 examples/data/uzbl/scripts/follow.js diff --git a/examples/data/uzbl/scripts/follow.js b/examples/data/uzbl/scripts/follow.js new file mode 100644 index 0000000..6b71372 --- /dev/null +++ b/examples/data/uzbl/scripts/follow.js @@ -0,0 +1,256 @@ +/* This is the basic linkfollowing script. + * + * TODO: check if all characters in follow_hint_keys from config + * are unique. + * 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 ;) + */ + +//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; + +//This string should be 10 unique characters long. Set it in your config +//with: +// set follow_hint_keys = asdfghjkl; # no quotes! +var defaultHintKeys = '0123456789'; +var hintKeys = Uzbl.run("print @follow_hint_keys") || defaultHintKeys; +if (hintKeys.length != 10) hintKeys = defaultHintKeys; + +//Reset keycmd, modcmd and return to default mode. +function clearKeycmd() { Uzbl.run('set mode ='); } + +//Make onclick-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(); + } +} +//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; + 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]; + var height = offset[3]; + 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() { + var elements = doc.getElementById(uzbldivid); + 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); + 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.padding = '1px'; + hint.style.position = 'absolute'; + hint.style.zIndex = '1000'; + hint.style.left = pos[1] + 'px'; + hint.style.top = pos[0] + 'px'; + var img = el.getElementsByTagName('img'); + if (img.length > 0) { + hint.style.left = pos[1] + img[0].width / 2 + 'px'; + } + hint.style.textDecoration = 'none'; + hint.style.webkitBorderRadius = '6px'; + // Play around with this, pretty funny things to do :) + hint.style.webkitTransform = 'scale(1) rotate(0deg) translate(-6px,-5px)'; + 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) +function clickElem(item) { + removeAllHints(); + clearKeycmd(); + if (item) { + var name = item.tagName; + if (name == 'A') { + item.click(); + window.location = item.href; + } else if (name == 'INPUT') { + var type = item.getAttribute('type').toUpperCase(); + if (type == 'TEXT' || type == 'FILE' || type == 'PASSWORD') { + item.focus(); + item.select(); + } else { + item.click(); + } + } else if (name == 'TEXTAREA' || name == 'SELECT') { + item.focus(); + item.select(); + } else { + item.click(); + window.location = item.href; + } + } +} +//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'].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); + } +} +//Map 0123456789 to hintKeys +function mapNumToHintKeys(label) { + label = label + ''; + for (var j = 0; j < label.length; j++) { + var pos = parseInt(label[j]); + label = label.replace(label[j], hintKeys[pos]); + } + return label; +} +//Map hintKeys to 0123456789 +function mapHintKeysToNum(label) { + label = label + ''; + for (var j = 0; j < label.length; j++) { + var pos = hintKeys.search(label[j]); + if (pos < 0 || pos > 9) return; // bad input, key not in hintKeys + label = label.replace(label[j], pos+''); + } + return parseInt(label); +} +//Put it all together +function followLinks(follow) { + var s = follow.split(''); + var linknr = mapHintKeysToNum(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 = (elems[0].length + '').length; + var oldDiv = doc.getElementById(uzbldivid); + var leftover = [[], []]; + if (linknr + 1 && s.length == len && linknr < elems[0].length && linknr >= 0) { + clickElem(elems[0][linknr]); + } else { + for (var j = 0; j < elems[0].length; j++) { + var b = true; + var label = j + ''; + var n = label.length; + for (n; n < len; n++) { + label = '0' + label; + } + label = mapNumToHintKeys(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); + } + } + reDrawHints(leftover, s.length); + } +} +followLinks('%s'); -- cgit v1.2.3 From ed7e5126df07826aac90869200e4f48ed6bb9336 Mon Sep 17 00:00:00 2001 From: tczy Date: Tue, 29 Dec 2009 18:40:42 +0200 Subject: fixed http://www.uzbl.org/bugs/index.php?do=details&task_id=165 using supplied patch --- examples/data/uzbl/scripts/insert_bookmark.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/data/uzbl/scripts/insert_bookmark.sh b/examples/data/uzbl/scripts/insert_bookmark.sh index e04e6d4..c34e7db 100755 --- a/examples/data/uzbl/scripts/insert_bookmark.sh +++ b/examples/data/uzbl/scripts/insert_bookmark.sh @@ -6,6 +6,8 @@ file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/bookmarks which zenity &>/dev/null || exit 2 entry=`zenity --entry --text="Add bookmark. add tags after the '\t', separated by spaces" --entry-text="$6 $7\t"` +exitstatus=$? +if [ $exitstatus -ne 0 ]; then exit $exitstatus; fi url=`echo $entry | awk '{print $1}'` # TODO: check if already exists, if so, and tags are different: ask if you want to replace tags -- cgit v1.2.3 From 41719db3a893189f68dbb97cc49df1fed1e1163a Mon Sep 17 00:00:00 2001 From: tczy Date: Wed, 30 Dec 2009 02:10:35 +0200 Subject: uzbl-tabbed bind '@' fix --- examples/data/uzbl/scripts/uzbl-tabbed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/data/uzbl/scripts/uzbl-tabbed b/examples/data/uzbl/scripts/uzbl-tabbed index bb9b9a2..d93a3f4 100755 --- a/examples/data/uzbl/scripts/uzbl-tabbed +++ b/examples/data/uzbl/scripts/uzbl-tabbed @@ -1010,7 +1010,7 @@ class UzblTabbed: instance.''' binds = [] - bind_format = r'bind %s = sh "echo \"%s\" > \"%s\""' + bind_format = r'@bind %s = sh "echo \"%s\" > \"%s\""' bind = lambda key, action: binds.append(bind_format % (key, action,\ self.fifo_socket)) -- cgit v1.2.3 From 7c5e8614c1e57ddb77bc74a078c8d1725e452620 Mon Sep 17 00:00:00 2001 From: tczy Date: Wed, 6 Jan 2010 05:58:18 +0200 Subject: add follow_hint_keys default setting of 0123456789 --- config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/config.h b/config.h index e9b9a8e..80ca29c 100644 --- a/config.h +++ b/config.h @@ -6,5 +6,6 @@ const struct { { "set title_format_short = \\@TITLE - Uzbl browser <\\@NAME>"}, { "set max_conns = 100"}, /* WebkitGTK default: 10 */ { "set max_conns_host = 6"}, /* WebkitGTK default: 2 */ +{ "set follow_hint_keys = 0123456789"}, { NULL } }; -- cgit v1.2.3 From 27ed5bd4959e5546bf1d44f17854d85b50dfe1e3 Mon Sep 17 00:00:00 2001 From: tczy Date: Wed, 6 Jan 2010 06:05:10 +0200 Subject: appropriate changes to the config example --- examples/config/uzbl/config | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/config/uzbl/config b/examples/config/uzbl/config index 9dc4a35..d696c19 100644 --- a/examples/config/uzbl/config +++ b/examples/config/uzbl/config @@ -281,9 +281,11 @@ set toggle_cmd_ins = @toggle_modes command insert @cbind u = spawn @scripts_dir/load_url_from_bookmarks.sh # --- Link following (similar to vimperator and konqueror) --- -@cbind fl* = script @scripts_dir/follow_Numbers.js %s -# Or number with strings instead of numbers: -@cbind fL* = script @scripts_dir/follow_Numbers_Strings.js %s +# Set custom keys you wish to use for navigation. Some common examples: +#set follow_hint_keys = qwerty +#set follow_hint_keys = asdfghjkl; +#set follow_hint_keys = thsnd-rcgmvwb/;789aefijkopquxyz234 +@cbind f* = script @scripts_dir/follow.js '%s @{follow_hint_keys}' @cbind Xs = js alert("hi"); -- cgit v1.2.3 From 90f440600dd6a080baf38e3a2b1519eb6bc14195 Mon Sep 17 00:00:00 2001 From: tczy Date: Wed, 6 Jan 2010 06:11:34 +0200 Subject: Jason's linkfollower with modifications: navigation keys are optionally set in Uzbl's config; code for one-hand navigation is commented out. --- examples/data/uzbl/scripts/follow.js | 107 ++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 47 deletions(-) diff --git a/examples/data/uzbl/scripts/follow.js b/examples/data/uzbl/scripts/follow.js index 6b71372..19a0a28 100644 --- a/examples/data/uzbl/scripts/follow.js +++ b/examples/data/uzbl/scripts/follow.js @@ -1,7 +1,6 @@ /* This is the basic linkfollowing script. + * Its pretty stable, only using numbers to navigate. * - * TODO: check if all characters in follow_hint_keys from config - * are unique. * 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 @@ -18,18 +17,7 @@ var doc = document; var win = window; var links = document.links; var forms = document.forms; - -//This string should be 10 unique characters long. Set it in your config -//with: -// set follow_hint_keys = asdfghjkl; # no quotes! -var defaultHintKeys = '0123456789'; -var hintKeys = Uzbl.run("print @follow_hint_keys") || defaultHintKeys; -if (hintKeys.length != 10) hintKeys = defaultHintKeys; - -//Reset keycmd, modcmd and return to default mode. -function clearKeycmd() { Uzbl.run('set mode ='); } - -//Make onclick-links "clickable" +//Make onlick-links "clickable" try { HTMLElement.prototype.click = function() { if (typeof this.onclick == 'function') { @@ -114,19 +102,19 @@ function generateHint(el, label) { 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.left = pos[1] + 'px'; - hint.style.top = pos[0] + 'px'; +// hint.style.textTransform = 'uppercase'; + hint.style.left = Math.max(-1, (pos[1] - (7 + label.length * 9))) + 'px'; + hint.style.top = (pos[0] + 1) + 'px'; var img = el.getElementsByTagName('img'); - if (img.length > 0) { - hint.style.left = pos[1] + img[0].width / 2 + 'px'; - } + //if (img.length > 0) { + //hint.style.top = pos[1] + img[0].height / 2 - 6 + 'px'; + //} hint.style.textDecoration = 'none'; - hint.style.webkitBorderRadius = '6px'; - // Play around with this, pretty funny things to do :) - hint.style.webkitTransform = 'scale(1) rotate(0deg) translate(-6px,-5px)'; + // hint.style.webkitBorderRadius = '6px'; // slow return hint; } //Here we choose what to do with an element if we @@ -135,7 +123,6 @@ function generateHint(el, label) { //but at least set the href of the link. (needs some improvements) function clickElem(item) { removeAllHints(); - clearKeycmd(); if (item) { var name = item.tagName; if (name == 'A') { @@ -201,47 +188,67 @@ function reDrawHints(elems, chars) { document.body.appendChild(hintdiv); } } -//Map 0123456789 to hintKeys -function mapNumToHintKeys(label) { - label = label + ''; - for (var j = 0; j < label.length; j++) { - var pos = parseInt(label[j]); - label = label.replace(label[j], hintKeys[pos]); - } - return label; +// pass: number of keys +// returns: key length +function labelLength(n) { + var oldn = n; + var keylen = 0; + 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; } -//Map hintKeys to 0123456789 -function mapHintKeysToNum(label) { - label = label + ''; - for (var j = 0; j < label.length; j++) { - var pos = hintKeys.search(label[j]); - if (pos < 0 || pos > 9) return; // bad input, key not in hintKeys - label = label.replace(label[j], pos+''); - } - return parseInt(label); +// pass: number +// returns: label +function intToLabel(n) { + var label = ''; + do { + label = charset.charAt(n % charset.length) + label; + n = Math.floor(n / charset.length); + } while(n); + return label; +} +// pass: label +// returns: number +function labelToInt(label) { + var n = 0; + var i; + for(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-/'; + // } var s = follow.split(''); - var linknr = mapHintKeysToNum(follow); + 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 = (elems[0].length + '').length; + var len = labelLength(elems[0].length); var oldDiv = doc.getElementById(uzbldivid); var leftover = [[], []]; - if (linknr + 1 && s.length == len && linknr < elems[0].length && linknr >= 0) { + if (s.length == len && linknr < elems[0].length && linknr >= 0) { clickElem(elems[0][linknr]); } else { for (var j = 0; j < elems[0].length; j++) { var b = true; - var label = j + ''; + var label = intToLabel(j); var n = label.length; for (n; n < len; n++) { - label = '0' + label; + label = charset.charAt(0) + label; } - label = mapNumToHintKeys(label); for (var k = 0; k < s.length; k++) { b = b && label.charAt(k) == s[k]; } @@ -253,4 +260,10 @@ function followLinks(follow) { reDrawHints(leftover, s.length); } } -followLinks('%s'); + +//Parse input: first argument is user input, second is allowed hint keys. +var args = '%s'.split(' '); +var following = args[0]; +var charset = args[1]; + +followLinks(following); -- cgit v1.2.3 From da244b530d8e99eae6766b3ff01bbd484929e4f7 Mon Sep 17 00:00:00 2001 From: tczy Date: Wed, 6 Jan 2010 06:12:18 +0200 Subject: remove follow scripts that are replaced by follow.js --- examples/data/uzbl/scripts/follow_Numbers.js | 228 --------------------- .../data/uzbl/scripts/follow_Numbers_Strings.js | 212 ------------------- 2 files changed, 440 deletions(-) delete mode 100644 examples/data/uzbl/scripts/follow_Numbers.js delete mode 100644 examples/data/uzbl/scripts/follow_Numbers_Strings.js diff --git a/examples/data/uzbl/scripts/follow_Numbers.js b/examples/data/uzbl/scripts/follow_Numbers.js deleted file mode 100644 index 00b279e..0000000 --- a/examples/data/uzbl/scripts/follow_Numbers.js +++ /dev/null @@ -1,228 +0,0 @@ -/* This is the basic linkfollowing script. - * Its pretty stable, only using numbers to navigate. - * - * 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 ;) - */ - -//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; - -//Reset keycmd, modcmd and return to default mode. -function clearKeycmd() { Uzbl.run('set mode ='); } - -//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(); - } -} -//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; - 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]; - var height = offset[3]; - 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() { - var elements = doc.getElementById(uzbldivid); - 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); - 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.padding = '1px'; - hint.style.position = 'absolute'; - hint.style.zIndex = '1000'; - hint.style.left = pos[1] + 'px'; - hint.style.top = pos[0] + 'px'; - var img = el.getElementsByTagName('img'); - if (img.length > 0) { - hint.style.left = pos[1] + img[0].width / 2 + 'px'; - } - hint.style.textDecoration = 'none'; - hint.style.webkitBorderRadius = '6px'; - // Play around with this, pretty funny things to do :) - hint.style.webkitTransform = 'scale(1) rotate(0deg) translate(-6px,-5px)'; - 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) -function clickElem(item) { - removeAllHints(); - clearKeycmd(); - if (item) { - var name = item.tagName; - if (name == 'A') { - item.click(); - window.location = item.href; - } else if (name == 'INPUT') { - var type = item.getAttribute('type').toUpperCase(); - if (type == 'TEXT' || type == 'FILE' || type == 'PASSWORD') { - item.focus(); - item.select(); - } else { - item.click(); - } - } else if (name == 'TEXTAREA' || name == 'SELECT') { - item.focus(); - item.select(); - } else { - item.click(); - window.location = item.href; - } - } -} -//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'].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); - } -} -//Put it all together -function followLinks(follow) { - var s = follow.split(''); - var linknr = parseInt(follow, 10); - 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 = (elems[0].length + '').length; - var oldDiv = doc.getElementById(uzbldivid); - var leftover = [[], []]; - if (linknr + 1 && s.length == len && linknr < elems[0].length && linknr >= 0) { - clickElem(elems[0][linknr]); - } else { - for (var j = 0; j < elems[0].length; j++) { - var b = true; - var label = j + ''; - var n = label.length; - for (n; n < len; n++) { - label = '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); - } - } - reDrawHints(leftover, s.length); - } -} -followLinks('%s'); diff --git a/examples/data/uzbl/scripts/follow_Numbers_Strings.js b/examples/data/uzbl/scripts/follow_Numbers_Strings.js deleted file mode 100644 index e50da5d..0000000 --- a/examples/data/uzbl/scripts/follow_Numbers_Strings.js +++ /dev/null @@ -1,212 +0,0 @@ -var uzblid = 'uzbl_link_hint'; -var uzbldivid = uzblid + '_div_container'; -var doc = document; -var win = window; -var links = document.links; -var forms = document.forms; - -//Reset keycmd, modcmd and return to default mode. -function clearKeycmd() { Uzbl.run('set mode ='); } - -try { - HTMLElement.prototype.click = function() { - if (typeof this.onclick == 'function') { - this.onclick({ - type: 'click' - }); - } - }; -} catch(e) {} -function keyPressHandler(e) { - var kC = window.event ? event.keyCode: e.keyCode; - var Esc = window.event ? 27 : e.DOM_VK_ESCAPE; - if (kC == Esc) { - removeAllHints(); - } -} -function elementPosition(el) { - 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]; -} -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); -} -function elementInViewport(el) { - offset = 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; -} -function removeAllHints() { - var elements = doc.getElementById(uzbldivid); - if (elements) { - elements.parentNode.removeChild(elements); - } -} -function generateHint(el, label) { - var pos = elementPosition(el); - var hint = doc.createElement('div'); - hint.setAttribute('name', uzblid); - hint.innerText = label; - hint.style.display = 'inline'; - hint.style.backgroundColor = '#B9FF00'; - hint.style.border = '2px solid #4A6600'; - hint.style.color = 'black'; - hint.style.zIndex = '1000'; - hint.style.fontSize = '9px'; - hint.style.fontWeight = 'bold'; - hint.style.lineHeight = '9px'; - hint.style.margin = '0px'; - hint.style.padding = '1px'; - hint.style.position = 'absolute'; - hint.style.left = pos[1] + 'px'; - hint.style.top = pos[0] + 'px'; - var img = el.getElementsByTagName('img'); - if (img.length > 0) { - hint.style.left = pos[1] + img[0].width / 2 + 'px'; - } - hint.style.textDecoration = 'none'; - hint.style.webkitBorderRadius = '6px'; - hint.style.webkitTransform = 'scale(1) rotate(0deg) translate(-6px,-5px)'; - return hint; -} - -function clickElem(item) { - removeAllHints(); - clearKeycmd(); - if (item) { - var name = item.tagName; - if (name == 'A') { - item.click(); - window.location = item.href; - } else if (name == 'INPUT') { - var type = item.getAttribute('type').toUpperCase(); - if (type == 'TEXT' || type == 'FILE' || type == 'PASSWORD') { - item.focus(); - item.select(); - } else { - item.click(); - } - } else if (name == 'TEXTAREA' || name == 'SELECT') { - item.focus(); - item.select(); - } else { - item.click(); - window.location = item.href; - } - } -} - -function addLinks() { - res = [[], []]; - for (var l = 0; l < links.length; l++) { - var li = links[l]; - if (isVisible(li) && elementInViewport(li)) { - res[0].push(li); - res[1].push(li.innerText.toLowerCase()); - } - } - return res; -} -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'].indexOf(el.tagName) + 1 && isVisible(el) && elementInViewport(el)) { - res[0].push(el); - if (el.getAttribute('value')) { - res[1].push(el.getAttribute('value').toLowerCase()); - } else { - res[1].push(el.getAttribute('name').toLowerCase()); - } - } - } - } - return res; -} -function reDrawHints(elems, len) { - var hintdiv = doc.createElement('div'); - hintdiv.setAttribute('id', uzbldivid); - hintdiv.style.opacity = '0.0'; - for (var i = 0; i < elems[0].length; i++) { - var label = i + ''; - var n = label.length; - for (n; n < len; n++) { - label = '0' + label; - } - if (elems[0][i]) { - var h = generateHint(elems[0][i], label); - hintdiv.appendChild(h); - } - } - if (document.body) { - document.body.appendChild(hintdiv); - hintdiv.style.opacity = '0.7' - } -} -function followLinks(follow) { - var s = follow.split(''); - var linknr = parseInt(follow, 10); - 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 = (elems[0].length + '').length; - var oldDiv = doc.getElementById(uzbldivid); - var leftover = [[], []]; - if (linknr + 1 && s.length == len && linknr < elems[0].length && linknr >= 0) { - clickElem(elems[0][linknr]); - } else { - for (var j = 0; j < elems[0].length; j++) { - var b = true; - for (var k = 0; k < s.length; k++) { - b = b && elems[1][j].charAt(k) == s[k]; - } - if (!b) { - elems[0][j] = null; - elems[1][j] = null; - } else { - leftover[0].push(elems[0][j]); - leftover[1].push(elems[1][j]); - } - } - if (leftover[0].length == 1) { - clickElem(leftover[0][0]); - } else if (!oldDiv) { - if (linknr + 1 || s.length == 0) { - reDrawHints(elems, len); - } else { - reDrawHints(leftover, len); - } - } - } -} -followLinks('%s'); -- cgit v1.2.3 From d08719163597747477ebe96fc63779373e8fe376 Mon Sep 17 00:00:00 2001 From: tczy Date: Wed, 6 Jan 2010 06:13:30 +0200 Subject: jason in authors --- AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index b63132c..8206029 100644 --- a/AUTHORS +++ b/AUTHORS @@ -39,7 +39,7 @@ In alphabetical order: Jake Probst - uzbl_tabbed: multiline tablist James S Wheaton (uranther) - zoom level, test framework Jan Kolkmeier (jouz) - scrolling, link following - Jason Woofenden (JasonWoof) - geometry=maximized + Jason Woofenden (JasonWoof) - geometry=maximized, link following Laurence Withers (lwithers) - talk_to_socket Mark Nevill - misc patches Mason Larobina - uzbl-tabbed.py, cookie-daemon, event-manager&plugins, ... -- cgit v1.2.3 From 2b2c04ab16923fda7111f36243c0fbf4e19587bc Mon Sep 17 00:00:00 2001 From: tczy Date: Wed, 6 Jan 2010 06:31:19 +0200 Subject: document follow_hint_keys --- README | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README b/README index 0d6ed04..ac044e4 100644 --- a/README +++ b/README @@ -192,7 +192,7 @@ Besides the builtin variables you can also define your own ones and use them in - `status_background`: color which can be used to override Gtk theme. - `insert_indicator`: string to denote insert mode TODO plugin variable - `command_indicator`: string to denote command mode TODO plugin variable - - `title_format_long`: titlebar string when no statusbar shown (will be expanded + - `title_format_long`: titlebar string when no statusbar shown (will be expanded) - `title_format_short`: titlebar string when statusbar shown (will be expanded) - `icon`: path to icon for Gtk - `forward_keys`: whether uzbl-core should send key events to the webkit view @@ -200,6 +200,7 @@ Besides the builtin variables you can also define your own ones and use them in - `always_insert_mode`: set this to true if you don't like modal (vim-like) interfaces TODO explain plugin variable - `reset_command_mode`: automatically revert to command mode on pageload (unless always_insert_mode is set) TODO explain plugin variable - `modkey`: modkey which can be pressed to activate keybind from inside insert mode + - `follow_hint_keys`: keys for keyboard-based navigation and link highlighting - `download_handler` - `cookie_handler` - `new_window`: handler to execute to invoke new uzbl window (TODO better name) -- cgit v1.2.3 From b073f78bbcb1bbf7699707aa1381df78737b06fc Mon Sep 17 00:00:00 2001 From: tczy Date: Wed, 6 Jan 2010 06:43:24 +0200 Subject: get back to default styles, github had a mess --- examples/data/uzbl/scripts/follow.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/data/uzbl/scripts/follow.js b/examples/data/uzbl/scripts/follow.js index 19a0a28..d697368 100644 --- a/examples/data/uzbl/scripts/follow.js +++ b/examples/data/uzbl/scripts/follow.js @@ -106,15 +106,17 @@ function generateHint(el, label) { hint.style.padding = '1px'; hint.style.position = 'absolute'; hint.style.zIndex = '1000'; -// hint.style.textTransform = 'uppercase'; - hint.style.left = Math.max(-1, (pos[1] - (7 + label.length * 9))) + 'px'; - hint.style.top = (pos[0] + 1) + 'px'; - var img = el.getElementsByTagName('img'); - //if (img.length > 0) { - //hint.style.top = pos[1] + img[0].height / 2 - 6 + 'px'; - //} + // 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)'; return hint; } //Here we choose what to do with an element if we -- cgit v1.2.3 From 9d53b1fcc0828b0359bdae606d79f3106b7cca49 Mon Sep 17 00:00:00 2001 From: tczy Date: Wed, 6 Jan 2010 06:58:28 +0200 Subject: remove unneeded var --- examples/data/uzbl/scripts/follow.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/data/uzbl/scripts/follow.js b/examples/data/uzbl/scripts/follow.js index d697368..12b3765 100644 --- a/examples/data/uzbl/scripts/follow.js +++ b/examples/data/uzbl/scripts/follow.js @@ -263,9 +263,8 @@ function followLinks(follow) { } } -//Parse input: first argument is user input, second is allowed hint keys. +//Parse input: first argument is user input, second is defined hint keys. var args = '%s'.split(' '); -var following = args[0]; var charset = args[1]; -followLinks(following); +followLinks(args[0]); -- cgit v1.2.3 From 5aa5cbdb8d12c6b2675e416f69ec36aaed7696c0 Mon Sep 17 00:00:00 2001 From: tczy Date: Tue, 19 Jan 2010 17:26:28 +0200 Subject: No script fluff should be in config.h, thanks mason. --- config.h | 1 - examples/config/uzbl/config | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/config.h b/config.h index 80ca29c..e9b9a8e 100644 --- a/config.h +++ b/config.h @@ -6,6 +6,5 @@ const struct { { "set title_format_short = \\@TITLE - Uzbl browser <\\@NAME>"}, { "set max_conns = 100"}, /* WebkitGTK default: 10 */ { "set max_conns_host = 6"}, /* WebkitGTK default: 2 */ -{ "set follow_hint_keys = 0123456789"}, { NULL } }; diff --git a/examples/config/uzbl/config b/examples/config/uzbl/config index f8a2058..e000015 100644 --- a/examples/config/uzbl/config +++ b/examples/config/uzbl/config @@ -296,7 +296,7 @@ set toggle_cmd_ins = @toggle_modes command insert # --- Link following (similar to vimperator and konqueror) --- # Set custom keys you wish to use for navigation. Some common examples: -#set follow_hint_keys = qwerty +set follow_hint_keys = qwerty #set follow_hint_keys = asdfghjkl; #set follow_hint_keys = thsnd-rcgmvwb/;789aefijkopquxyz234 @cbind f* = script @scripts_dir/follow.js '%s @{follow_hint_keys}' -- cgit v1.2.3 From 1f9dc0bb9d125449eb578dacb0bd3d50885292d6 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 24 Jan 2010 15:29:27 +0100 Subject: unbreak test suite --- tests/test-command.c | 4 ++-- tests/test-expand.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test-command.c b/tests/test-command.c index fc3b092..6194081 100644 --- a/tests/test-command.c +++ b/tests/test-command.c @@ -22,8 +22,8 @@ #include #include -#include -#include +#include +#include extern UzblCore uzbl; diff --git a/tests/test-expand.c b/tests/test-expand.c index ef07c80..4dcd82d 100644 --- a/tests/test-expand.c +++ b/tests/test-expand.c @@ -22,8 +22,8 @@ #include #include -#include -#include +#include +#include extern UzblCore uzbl; -- cgit v1.2.3