code examples for custom keys

Showing 1-2 of 2 messages
code examples for custom keys Rahul Abrol 8/28/12 1:43 AM
1. say you want a key that scrolls half a page (like in vi).  the code would look something like:

window.scrollBy(0, window.innerHeight / 2)

this won't work in safari reader though, so use the internal "scroll" function instead:

scroll(this, 0, window.innerHeight / 2)

(you can examine KS's internal functions by looking at end.js in the web inspector).

2. say you want a key to do something different on one particular site:

if ( == "")

this creates a Focus Field keystroke on all sites except planet webkit, where hitting the key would instead take you to the safari blog.
Re: code examples for custom keys Rahul Abrol 8/30/12 1:37 AM
3. here's a more complex example to enable Page Down on gmail.  several steps are required:

a. remove from the list of Disabled Sites.
b. add to the list of Force Active Automatically (since it uses frames).
c. change the list of Disabled Elements to an asterisk * (otherwise it conflicts with composing mail).

finally, create a new key with (roughly) this code:

if ( == "")
    scroll(document.getElementById(":rp"), 0, window.innerHeight / 2);
    scroll(this, 0, window.innerHeight-keys.bool.pagepx)

and remember to clear your old Page Down keystroke.