From f538ef4bbedda04a73dbc44e5f1abca09a4ba359 Mon Sep 17 00:00:00 2001 From: Mason Larobina Date: Sat, 13 Mar 2010 23:00:59 +0800 Subject: Removed broken and deprecated scripts and removed them from the config. examples/scripts/cookies.sh: Deprecated by uzbl-cookie-daemon months ago. examples/scripts/extedit.js: Broken in its current form without the Uzbl.run method. examples/scripts/scroll-percentage.js: Broken without the Uzbl.run method. examples/scripts/{linkfollow,hint,follower}.js: Development should take place in the single follow.js from now on. There is no logic in co-developing 4 separate following scripts (some of which have been broken for months) in our selection of example scripts. --- examples/config/config | 10 - examples/data/scripts/cookies.sh | 154 ----------- examples/data/scripts/extedit.js | 102 ------- examples/data/scripts/follower.js | 420 ----------------------------- examples/data/scripts/hint.js | 26 -- examples/data/scripts/linkfollow.js | 269 ------------------ examples/data/scripts/scroll-percentage.js | 68 ----- 7 files changed, 1049 deletions(-) delete mode 100755 examples/data/scripts/cookies.sh delete mode 100644 examples/data/scripts/extedit.js delete mode 100644 examples/data/scripts/follower.js delete mode 100644 examples/data/scripts/hint.js delete mode 100644 examples/data/scripts/linkfollow.js delete mode 100644 examples/data/scripts/scroll-percentage.js (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index d52e65b..576e674 100644 --- a/examples/config/config +++ b/examples/config/config @@ -62,7 +62,6 @@ set new_window = sh 'uzbl-browser -u $8' # Load commit handlers @on_event LOAD_COMMIT @set_status recv -#@on_event LOAD_COMMIT script @scripts_dir/scroll-percentage.js # Load finish handlers @on_event LOAD_FINISH @set_status done @@ -339,15 +338,6 @@ set eFormFiller = spawn @scripts_dir/eFormFiller.sh @cbind ZN = @eFormFiller new @cbind ZL = @eFormFiller load -# --- External edit script configuration & binds --- -# Edit form input fields in an external editor (gvim, emacs, urxvt -e vim, ..) -# disabled since Uzbl object is gone -set external_editor = gvim -#set external_editor = xterm -e vim -#@cbind E = script @scripts_dir/extedit.js -# And add menu option. -#menu_editable_add Open in @external_editor = script @scripts_dir/extedit.js - # --- Examples --- # Example showing how to use uzbl's fifo to execute a command. #@bind X1 = sh 'echo "set zoom_level = 1.0" > "$4"' diff --git a/examples/data/scripts/cookies.sh b/examples/data/scripts/cookies.sh deleted file mode 100755 index ee2ce51..0000000 --- a/examples/data/scripts/cookies.sh +++ /dev/null @@ -1,154 +0,0 @@ -#!/bin/sh - -set -n; - -# THIS IS EXPERIMENTAL AND COULD BE INSECURE !!!!!! - -# this is an example bash script of how you could manage your cookies. it is very raw and basic and not as good as uzbl-cookie-daemon -# we use the cookies.txt format (See http://kb.mozillazine.org/Cookies.txt) -# This is one textfile with entries like this: -# kb.mozillazine.org FALSE / FALSE 1146030396 wikiUserID 16993 -# domain alow-read-other-subdomains path http-required expiration name value -# you probably want your cookies config file in your $XDG_CONFIG_HOME ( eg $HOME/.config/uzbl/cookies) -# Note. in uzbl there is no strict definition on what a session is. it's YOUR job to clear cookies marked as end_session if you want to keep cookies only valid during a "session" -# MAYBE TODO: allow user to edit cookie before saving. this cannot be done with zenity :( -# TODO: different cookie paths per config (eg per group of uzbl instances) - -# TODO: correct implementation. -# see http://curl.haxx.se/rfc/cookie_spec.html -# http://en.wikipedia.org/wiki/HTTP_cookie - -# TODO : check expires= before sending. -# write sample script that cleans up cookies dir based on expires attribute. -# TODO: check uri against domain attribute. and path also. -# implement secure attribute. -# support blocking or not for 3rd parties -# http://kb.mozillazine.org/Cookies.txt -# don't always append cookies, sometimes we need to overwrite - -cookie_config=${XDG_CONFIG_HOME:-${HOME}/.config}/uzbl/cookies -[ "x$cookie_config" = x ] && exit 1 -[ -d "${XDG_DATA_HOME:-${HOME}/.local/share}/uzbl/" ] &&\ -cookie_data=${XDG_DATA_HOME:-${HOME}/.local/share}/uzbl/cookies.txt || exit 1 - -notifier= -#notifier=notify-send -#notify_wrapper () { -# echo "$@" >> $HOME/cookielog -#} -#notifier=notifier_wrapper - -# if this variable is set, we will use it to inform you when and which cookies we store, and when/which we send. -# it's primarily used for debugging -notifier= -which zenity &>/dev/null || exit 2 - -# Example cookie: -# test_cookie=CheckForPermission; expires=Thu, 07-May-2009 19:17:55 GMT; path=/; domain=.doubleclick.net - -# uri=$6 -# uri=${uri/http:\/\/} # strip 'http://' part -# host=${uri/\/*/} -action=$8 # GET/PUT -shift -host=$9 -shift -path=$9 -shift -cookie=$9 - -field_domain=$host -field_path=$path -field_name= -field_value= -field_exp='end_session' - -notify() { - [ -n "$notifier" ] && $notifier "$@" -} - - -# FOR NOW LETS KEEP IT SIMPLE AND JUST ALWAYS PUT AND ALWAYS GET -parse_cookie() { - IFS=$';' - first_pair=1 - for pair in $cookie - do - if [ "x$first_pair" = x1 ] - then - field_name=${pair%%=*} - field_value=${pair#*=} - first_pair=0 - else - echo "$pair" | read -r pair #strip leading/trailing wite space - key=${pair%%=*} - val=${pair#*=} - [ "$key" == expires ] && field_exp=`date -u -d "$val" +'%s'` - # TODO: domain - [ "$key" == path ] && field_path=$val - fi - done - unset IFS -} - -# match cookies in cookies.txt against hostname and path -get_cookie() { - path_esc=${path//\//\\/} - search="^[^\t]*$host\t[^\t]*\t$path_esc" - cookie=`awk "/$search/" $cookie_data 2>/dev/null | tail -n 1` - if [ -z "$cookie" ] - then - notify "Get_cookie: search: $search in $cookie_data -> no result" - false - else - notify "Get_cookie: search: $search in $cookie_data -> result: $cookie" - echo "$cookie" | \ - read domain alow_read_other_subdomains path http_required expiration name \ - value; - cookie="$name=$value" - true - fi -} - -save_cookie() { - if parse_cookie - then - data="$field_domain\tFALSE\t$field_path\tFALSE\t$field_exp\t$field_name\t$field_value" - notify "save_cookie: adding $data to $cookie_data" - echo -e "$data" >> $cookie_data - else - notify "not saving a cookie. since we don't have policies yet, parse_cookie must have returned false. this is a bug" - fi -} - -[ "x$action" = xPUT ] && save_cookie -[ "x$action" = xGET ] && get_cookie && echo "$cookie" - -exit - - -# TODO: implement this later. -# $1 = section (TRUSTED or DENY) -# $2 =url -match() { - sed -n "/$1/,/^\$/p" $cookie_config 2>/dev/null | grep -q "^$host" -} - -fetch_cookie() { - cookie=`cat $cookie_data` -} - -store_cookie() { - echo $cookie > $cookie_data -} - -if match TRUSTED $host -then - [ "x$action" = xPUT ] && store_cookie $host - [ "x$action" = xGET ] && fetch_cookie && echo "$cookie" -elif ! match DENY $host -then - [ "x$action" = xPUT ] && cookie=`zenity --entry --title 'Uzbl Cookie handler' --text "Accept this cookie from $host ?" --entry-text="$cookie"` && store_cookie $host - [ "x$action" = xGET ] && fetch_cookie && cookie=`zenity --entry --title 'Uzbl Cookie handler' --text "Submit this cookie to $host ?" --entry-text="$cookie"` && echo $cookie -fi -exit 0 diff --git a/examples/data/scripts/extedit.js b/examples/data/scripts/extedit.js deleted file mode 100644 index 8ed346d..0000000 --- a/examples/data/scripts/extedit.js +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Edit forms in external editor - * - * (c) 2009, Robert Manea - * utf8 functions are (c) by Webtoolkit.info (http://www.webtoolkit.info/) - * - * - * Installation: - * - Copy this script to $HOME/.local/share/uzbl/scripts - * - Add the following to $HOME/.config/uzbl/config: - * @bind E = script @scripts_dir/extedit.js - * - Set your preferred editor - * set editor = gvim - * - non-GUI editors - * set editor = xterm -e vim - * - * Usage: - * Select (click) an editable form, go to command mode and hit E - * -*/ - - -function utf8_decode ( str_data ) { - var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0; - - str_data += ''; - - while ( i < str_data.length ) { - c1 = str_data.charCodeAt(i); - if (c1 < 128) { - tmp_arr[ac++] = String.fromCharCode(c1); - i++; - } else if ((c1 > 191) && (c1 < 224)) { - c2 = str_data.charCodeAt(i+1); - tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63)); - i += 2; - } else { - c2 = str_data.charCodeAt(i+1); - c3 = str_data.charCodeAt(i+2); - tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); - i += 3; - } - } - - return tmp_arr.join(''); -} - - -function utf8_encode ( argString ) { - var string = (argString+''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n"); - - var utftext = ""; - var start, end; - var stringl = 0; - - start = end = 0; - stringl = string.length; - for (var n = 0; n < stringl; n++) { - var c1 = string.charCodeAt(n); - var enc = null; - - if (c1 < 128) { - end++; - } else if (c1 > 127 && c1 < 2048) { - enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128); - } else { - enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128); - } - if (enc !== null) { - if (end > start) { - utftext += string.substring(start, end); - } - utftext += enc; - start = end = n+1; - } - } - - if (end > start) { - utftext += string.substring(start, string.length); - } - - return utftext; -} - - -(function() { - var actelem = document.activeElement; - - if(actelem.type == 'text' || actelem.type == 'textarea') { - var editor = Uzbl.run("print @external_editor") || "gvim"; - var filename = Uzbl.run("print @(mktemp /tmp/uzbl_edit.XXXXXX)@"); - - if(actelem.value) - Uzbl.run("sh 'echo " + window.btoa(utf8_encode(actelem.value)) + " | base64 -d > " + filename + "'"); - - Uzbl.run("sync_sh '" + editor + " " + filename + "'"); - actelem.value = utf8_decode(window.atob(Uzbl.run("print @(base64 -w 0 " + filename + ")@"))); - - Uzbl.run("sh 'rm -f " + filename + "'"); - } - - })(); diff --git a/examples/data/scripts/follower.js b/examples/data/scripts/follower.js deleted file mode 100644 index dc37b46..0000000 --- a/examples/data/scripts/follower.js +++ /dev/null @@ -1,420 +0,0 @@ -// A Link Follower for Uzbl. -// P.C. Shyamshankar -// -// WARNING: this script depends on the Uzbl object which is now disabled for -// WARNING security reasons. So the script currently doesn't work but it's -// WARNING interesting nonetheless -// -// Based extensively (like copy-paste) on the follow_numbers.js and -// linkfollow.js included with uzbl, but modified to be more customizable and -// extensible. -// -// Usage -// ----- -// -// First, you'll need to make sure the script is loaded on each page. This can -// be done with: -// -// @on_event LOAD_COMMIT script /path/to/follower.js -// -// Then you can bind it to a key: -// -// @bind f* = js follower.follow('%s', matchSpec, handler, hintStyler) -// -// where matchSpec, handler and hintStyler are parameters which control the -// operation of follower. If you don't want to customize any further, you can -// set these to follower.genericMatchSpec, follower.genericHandler and -// follower.genericHintStyler respectively. -// -// For example, -// -// @bind f* = js follower.follow('%s', follower.genericMatchSpec, follower.genericHandler, follower.genericHintStyler) -// @bind F* = js follower.follow('%s', follower.onlyLinksMatchSpec, follower.newPageHandler, follower.newPageHintStyler) -// -// In order to make hints disappear when pressing a key (the Escape key, for -// example), you can do this: -// -// @bind = js follower.clearHints() -// -// If your Escape is already bound to something like command mode, chain it. -// -// Alternatively, you can tell your key to emit an event, and handle -// that instead. -// -// @bind = event ESCAPE -// @on_event ESCAPE js follower.clearHints() -// -// Customization -// ------------- -// -// If however you do want to customize, 3 Aspects of the link follower can be -// customized with minimal pain or alteration to the existing code base: -// -// * What elements are hinted. -// * The style of the hints displayed. -// * How the hints are handled. -// -// In order to customize behavior, write an alternative, and pass that in to -// follower.follow invocation. You _will_ have to modify this script, but only -// locally, it beats having to copy the entire script under a new name and -// modify. -// -// TODO: -// * Whatever all the other TODOs in the file say. -// * Find out how to do default arguments in Javascript. -// * Abstract out the hints into a Hint object, make hintables a list of hint -// objects instead of two lists. - -// Helpers -String.prototype.lpad = function(padding, length) { - var padded = this; - while (padded.length < length) { - padded = padding + padded; - } - - return padded; -} - -function Follower() { - - // Globals - var uzblID = 'uzbl-follow'; // ID to apply to each hint. - var uzblContainerID = 'uzbl-follow-container'; // ID to apply to the div containing hints. - - // Translation table, used to display something other than numbers as hint - // labels. Typically set to the ten keys of the home row. - // - // Must have exactly 10 elements. - // - // I haven't parameterized this, to make it customizable. Should I? Do - // people really use more than one set of keys at a time? - var translation = ["a", "r", "s", "t", "d", "h", "n", "e", "i", "o"]; - - // MatchSpecs - // These are XPath expressions which indicate which elements will be hinted. - // Use multiple expressions for different situations, like hinting only form - // elements, or only links, etc. - // - // TODO: Check that these XPath expressions are correct, and optimize/make - // them more elegant. Preferably by someone who actually knows XPath, unlike - // me. - - // Vimperator default (copy-pasted, I never used vimperator). - this.genericMatchSpec = " //*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @role='link' or @href] | //input[not(@type='hidden')] | //a | //area | //iframe | //textarea | //button | //select"; - - // Matches only links, suitable for opening in a new instance (I think). - this.onlyLinksMatchSpec = " //*[@href] | //a | //area"; - - // Follow Handlers - // These decide how an element should be 'followed'. The handler is passed - // the element in question. - - // Generic Handler, opens links in the same instance, emits the FORM_ACTIVE - // event if a form element was chosen. Also clears the keycmd. - this.genericHandler = function(node) { - if (node) { - if (window.itemClicker != undefined) { - window.itemClicker(node); - } else { - var tag = node.tagName.toLowerCase(); - if (tag == 'a') { - node.click(); - window.location = node.href; - } else if (tag == 'input') { - var inputType = node.getAttribute('type'); - if (inputType == undefined) - inputType = 'text'; - - inputType = inputType.toLowerCase(); - - if (inputType == 'text' || inputType == 'file' || inputType == 'password') { - node.focus(); - node.select(); - } else { - node.click(); - } - Uzbl.run("event FORM_ACTIVE"); - } else if (tag == 'textarea'|| tag == 'select') { - node.focus(); - node.select(); - Uzbl.run("event FORM_ACTIVE"); - } else { - node.click(); - if ((node.href != undefined) && node.href) - window.location = node.href; - } - } - } - Uzbl.run("event SET_KEYCMD"); - } - - // Handler to open links in a new page. The rest is the same as before. - this.newPageHandler = function(node) { - if (node) { - if (window.itemClicker != undefined) { - window.itemClicker(node); - } else { - var tag = node.tagName.toLowerCase(); - if (tag == 'a') { - node.click(); - Uzbl.run("@new_window " + node.href); - } else if (tag == 'input') { - var inputType = node.getAttribute('type'); - if (inputType == undefined) - inputType = 'text'; - - inputType = inputType.toLowerCase(); - - if (inputType == 'text' || inputType == 'file' || inputType == 'password') { - node.focus(); - node.select(); - } else { - node.click(); - } - Uzbl.run("event FORM_ACTIVE"); - } else if (tag == 'textarea'|| tag == 'select') { - node.focus(); - node.select(); - Uzbl.run("event FORM_ACTIVE"); - } else { - node.click(); - if ((node.href != undefined) && node.href) - window.location = node.href; - } - } - } - Uzbl.run("event SET_KEYCMD"); - }; - - // Hint styling. - // Pretty much any attribute of the hint object can be modified here, but it - // was meant to change the styling. Useful to differentiate between hints - // with different handlers. - // - // Hint stylers are applied at the end of hint creation, so that they - // override the defaults. - - this.genericHintStyler = function(hint) { - hint.style.backgroundColor = '#AAAAAA'; - hint.style.border = '2px solid #4A6600'; - hint.style.color = 'black'; - hint.style.fontSize = '10px'; - hint.style.fontWeight = 'bold'; - hint.style.lineHeight = '12px'; - return hint; - }; - - this.newPageHintStyler = function(hint) { - hint.style.backgroundColor = '#FFCC00'; - hint.style.border = '2px solid #4A6600'; - hint.style.color = 'black'; - hint.style.fontSize = '10px'; - hint.style.fontWeight = 'bold'; - hint.style.lineHeight = '12px'; - return hint; - }; - - // Beyond lies a jungle of pasta and verbosity. - - // Translate a numeric label using the translation table. - function translate(digitLabel, translationTable) { - translatedLabel = ''; - for (var i = 0; i < digitLabel.length; i++) { - translatedLabel += translationTable[digitLabel.charAt(i)]; - } - - return translatedLabel; - } - - function computeElementPosition(element) { - var up = element.offsetTop; - var left = element.offsetLeft; - var width = element.offsetWidth; - var height = element.offsetHeight; - - while (element.offsetParent) { - element = element.offsetParent; - up += element.offsetTop; - left += element.offsetLeft; - } - - return {up: up, left: left, width: width, height: height}; - } - - // Pretty much copy-pasted from every other link following script. - function isInViewport(element) { - offset = computeElementPosition(element); - - var up = offset.up; - var left = offset.left; - var width = offset.width; - var height = offset.height; - - return up < window.pageYOffset + window.innerHeight && - left < window.pageXOffset + window.innerWidth && - (up + height) > window.pageYOffset && - (left + width) > window.pageXOffset; - } - - function isVisible(element) { - if (element == document) { - return true; - } - - if (!element){ - return false; - } - - if (element.style) { - if (element.style.display == 'none' || element.style.visibiilty == 'hidden') { - return false; - } - } - - return isVisible(element.parentNode); - } - - function generateHintContainer() { - var container = document.getElementById(uzblContainerID); - if (container) { - container.parentNode.removeChild(container); - } - - container = document.createElement('div'); - container.id = uzblContainerID; - - if (document.body) { - document.body.appendChild(container); - } - return container; - } - - // Generate everything that is to be hinted, as per the given matchSpec. - // hintables[0] refers to the items, hintables[1] to their labels. - function generateHintables(matchSpec) { - var hintables = [[], []]; - - var itemsFromXPath = document.evaluate(matchSpec, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); - - for (var i = 0; i < itemsFromXPath.snapshotLength; ++i) { - var element = itemsFromXPath.snapshotItem(i); - if (element && isVisible(element) && isInViewport(element)) { - hintables[0].push(element); - } - } - - // Assign labels to each hintable. Can't be combined with the previous - // step, because we didn't know how many there were at that time. - var hintLength = hintables.length; - for (var i = 0; i < hintables[0].length; ++i) { - var code = translate(i.toString(), translation); - hintables[1].push(code.lpad(translation[0], hintLength)); - } - - return hintables; - } - - // Filter the hintables based on input from the user. Makes the screen less - // cluttered after the user has typed some prefix of hint labels. - function filterHintables(hintables, target) { - var filtered = [[], []]; - - var targetPattern = new RegExp("^" + target); - - for (var i = 0; i < hintables[0].length; i++) { - if (hintables[1][i].match(targetPattern)) { - filtered[0].push(hintables[0][i]); - filtered[1].push(hintables[1][i].substring(target.length)); - } - } - - return filtered; - } - - // TODO make this use the container variable from main, instead of searching - // for it? - function clearHints() { - var container = document.getElementById(uzblContainerID); - if (container) { - container.parentNode.removeChild(container); - } - } - - // So that we can offer this as a separate function. - this.clearHints = clearHints; - - function makeHint(node, code, styler) { - var position = computeElementPosition(node); - var hint = document.createElement('div'); - - hint.name = uzblID; - hint.innerText = code; - hint.style.display = 'inline'; - - hint.style.margin = '0px'; - hint.style.padding = '1px'; - hint.style.position = 'absolute'; - hint.style.zIndex = '10000'; - - hint.style.left = position.left + 'px'; - hint.style.top = position.up + 'px'; - - var img = node.getElementsByTagName('img'); - if (img.length > 0) { - hint.style.left = position.left + img[0].width / 2 + 'px'; - } - - hint.style.textDecoration = 'none'; - hint.style.webkitBorderRadius = '6px'; - hint.style.webkitTransform = 'scale(1) rotate(0deg) translate(-6px, -5px)'; - - hint = styler(hint); // So that custom hint stylers can override the above. - return hint; - } - - - function drawHints(container, hintables, styler) { - for (var i = 0; i < hintables[0].length; i++) { - hint = makeHint(hintables[0][i], hintables[1][i], styler); - container.appendChild(hint); - } - - if (document.body) { - document.body.appendChild(container); - } - } - - // The main hinting function. I don't know how to do default values to - // functions, so all arguments must be specified. Use generics if you must. - this.follow = function(target, matchSpec, handler, hintStyler) { - var container = generateHintContainer(); // Get a container to hold all hints. - var allHintables = generateHintables(matchSpec); // Get all items that can be hinted. - hintables = filterHintables(allHintables, target); // Filter them based on current input. - - clearHints(); // Clear existing hints, if any. - - if (hintables[0].length == 0) { - // Nothing was hinted, user pressed an unknown key, maybe? - // Do nothing. - } else if (hintables[0].length == 1) { - handler(hintables[0][0]); // Only one hint remains, handle it. - } else { - drawHints(container, hintables, hintStyler); // Draw whatever hints remain. - } - - return; - }; -} - -// Make on-click links clickable. -try { - HTMLElement.prototype.click = function() { - if (typeof this.onclick == 'function') { - this.onclick({ - type: 'click' - }); - } - }; -} catch(e) {} - -follower = new Follower(); diff --git a/examples/data/scripts/hint.js b/examples/data/scripts/hint.js deleted file mode 100644 index ec7f1e2..0000000 --- a/examples/data/scripts/hint.js +++ /dev/null @@ -1,26 +0,0 @@ -for (var i=0; i < document.links.length; i++) { - var uzblid = 'uzbl_link_hint_'; - var li = document.links[i]; - var pre = document.getElementById(uzblid+i); - - if (pre) { - li.removeChild(pre); - } else { - var hint = document.createElement('div'); - hint.setAttribute('id',uzblid+i); - hint.innerHTML = i; - hint.style.display='inline'; - hint.style.lineHeight='90%'; - hint.style.backgroundColor='red'; - hint.style.color='white'; - hint.style.fontSize='small-xx'; - hint.style.fontWeight='light'; - hint.style.margin='0px'; - hint.style.padding='2px'; - hint.style.position='absolute'; - hint.style.textDecoration='none'; - hint.style.left=li.style.left; - hint.style.top=li.style.top; - li.insertAdjacentElement('afterBegin',hint); - } -} diff --git a/examples/data/scripts/linkfollow.js b/examples/data/scripts/linkfollow.js deleted file mode 100644 index 3109cda..0000000 --- a/examples/data/scripts/linkfollow.js +++ /dev/null @@ -1,269 +0,0 @@ -// link follower for uzbl -// requires http://github.com/DuClare/uzbl/commit/6c11777067bdb8aac09bba78d54caea04f85e059 -// -// first, it needs to be loaded before every time it is used. -// One way would be to use the load_commit_handler: -// set load_commit_handler = sh 'echo "script /usr/share/uzbl/examples/data/scripts/linkfollow.js" > "$4"' -// -// when script is loaded, it can be invoked with -// bind f* = js hints.set("%s", hints.open) -// bind f_ = js hints.follow("%s",hints.open) -// -// At the moment, it may be useful to have way of forcing uzbl to load the script -// bind :lf = script /usr/share/uzbl/examples/data/scripts/linkfollow.js -// -// The default style for the hints are pretty ugly, so it is recommended to add the following -// to config file -// set stylesheet_uri = /usr/share/uzbl/examples/data/style.css -// -// based on follow_Numbers.js -// -// TODO: fix styling for the first element -// TODO: emulate mouseover events when visiting some elements -// TODO: rewrite the element->action handling - - -function Hints(){ - - // Settings - //////////////////////////////////////////////////////////////////////////// - - // if set to true, you must explicitly call hints.follow(), otherwise it will - // follow the link if there is only one matching result - var requireReturn = true; - - // Case sensitivity flag - var matchCase = "i"; - - // For case sensitive matching, uncomment: - // var matchCase = ""; - - - var uzblid = 'uzbl_hint'; - var uzblclass = 'uzbl_highlight'; - var uzblclassfirst = 'uzbl_h_first'; - var doc = document; - var visible = []; - var hintdiv; - - this.set = hint; - this.follow = follow; - this.keyPressHandler = keyPressHandler; - - 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: up, left: left, width: width, height: height}; - } - - function elementInViewport(p) { - return (p.up < window.pageYOffset + window.innerHeight && - p.left < window.pageXOffset + window.innerWidth && - (p.up + p.height) > window.pageYOffset && - (p.left + p.width) > window.pageXOffset); - } - - 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); - } - - // the vimperator defaults minus the xhtml elements, since it gave DOM errors - var hintable = " //*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @role='link' or @href] | //input[not(@type='hidden')] | //a | //area | //iframe | //textarea | //button | //select"; - - function Matcher(str){ - var numbers = str.replace(/[^\d]/g,""); - var words = str.replace(/\d/g,"").split(/\s+/).map(function (n) { return new RegExp(n,matchCase)}); - this.test = test; - this.toString = toString; - this.numbers = numbers; - function matchAgainst(element){ - if(element.node.nodeName == "INPUT"){ - return element.node.value; - } else { - return element.node.textContent; - } - } - function test(element) { - // test all the regexp - var item = matchAgainst(element); - return words.every(function (regex) { return item.match(regex)}); - } - } - - function HintElement(node,pos){ - - this.node = node; - this.isHinted = false; - this.position = pos; - this.num = 0; - - this.addHint = function (labelNum) { - // TODO: fix uzblclassfirst - if(!this.isHinted){ - this.node.className += " " + uzblclass; - } - this.isHinted = true; - - // create hint - var hintNode = doc.createElement('div'); - hintNode.name = uzblid; - hintNode.innerText = labelNum; - hintNode.style.left = this.position.left + 'px'; - hintNode.style.top = this.position.up + 'px'; - hintNode.style.position = "absolute"; - doc.body.firstChild.appendChild(hintNode); - - } - this.removeHint = function(){ - if(this.isHinted){ - var s = (this.num)?uzblclassfirst:uzblclass; - this.node.className = this.node.className.replace(new RegExp(" "+s,"g"),""); - this.isHinted = false; - } - } - } - - function createHintDiv(){ - var hintdiv = doc.getElementById(uzblid); - if(hintdiv){ - hintdiv.parentNode.removeChild(hintdiv); - } - hintdiv = doc.createElement("div"); - hintdiv.setAttribute('id',uzblid); - doc.body.insertBefore(hintdiv,doc.body.firstChild); - return hintdiv; - } - - function init(){ - // WHAT? - doc.body.setAttribute("onkeyup","hints.keyPressHandler(event)"); - hintdiv = createHintDiv(); - visible = []; - - var items = doc.evaluate(hintable,doc,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null); - for (var i = 0;i= height) { - message = run("print @scroll_bottom_indicator") || "Bot"; - } - else { - var percentage = Math.round(scrollY / (height - innerHeight) * 100); - message = percentage + "%"; - } - run("set scroll_message=" + message); - }; - - self.UzblZoom = { - get level() { - return Number(run("print @zoom_level")) || 1; - }, - set level(level) { - if (typeof level === "number" && level > 0) { - run("set zoom_level = " + level); - update_message(); - } - }, - get type() { - return run("print @zoom_type") || "text"; - }, - set type(type) { - if ((type === "text" || type === "full") && this.type != type) { - run("toggle_zoom_type"); - run("set zoom_type = " + type); - update_message(); - } - }, - toggle_type: function() { - this.type = (this.type === "text" ? "full" : "text"); - } - }; - - window.addEventListener("DOMContentLoaded", update_message, false); - window.addEventListener("load", update_message, false); - window.addEventListener("resize", update_message, false); - window.addEventListener("scroll", update_message, false); - update_message(); -})(); - -// vim: set noet ff=unix -- cgit v1.2.3