feb
1
6
“Back and Forth” Greasemonkey For The Whole Web
Recently I wrote a Greasemonkey script to add keyboard shortcuts to The Big Picture, to improve on some of their already existing shortcuts. Once I started using some of the shortcuts I made I ended up wanting to use them all over the place at other blogs. This functionality is so tiny, but so useful, that I bundled it into its own script that runs on all web pages!
//
// ==UserScript==
// @name Back and Forth
// @namespace http://blog.bogojoker.com
// @description Keyboard Shortcut to Jump back and forth on a page. (esc key).
// @include *
// @version 1.0 - Initial Version - Sunday February 15, 2009
// ==/UserScript==
// Global States
var x = null;
var y = null;
// Add a new Global Key Listener for `esc`
document addEventListener"keypress"
if!e e=windowevent;
var key = e keyCode ? e keyCode : e which;
if key == 27
var tempx = x;
var tempy = y;
x = MathmaxdocumentdocumentElement scrollLeft documentbody scrollLeft;
y = MathmaxdocumentdocumentElement scrollTop documentbody scrollTop;
if tempx != null // First time it should be null
windowscrollTo tempx tempy;
true;
;
On any webpage the first time you push the `esc` key position A gets stored. The next time you push `esc` position B gets stored and the browser jumps to position A. The next time you push it, A gets stored and you jump to B. So you always jump back to wherever you pushed `esc` last. Hence the name “back and forth.”
This is useful to me when I jump between comments and the content. When I’m reading a comment and I want to check back to the article, I just just push `esc` to save my position, go back to the article, and when I’m all set I just jump back to my saved position (the comments) with `esc`.
Short, Sweet, Simple: The Back and Forth Greasemonkey Script.
sldx on March 24, 2010 at 12:34 pm #
This sounds like a great idea but it doesn’t seem to work. Any idea why?
mac 10.5, ffox 3.6