User:Tmopkisn/jumpdown.js

var xp_anchors; var anchorCount; var curAnchor; var faderTimer;

window.addEventListener('load', main, false); window.addEventListener('keypress', keyHandler, false);

function main { xp_anchors = document.evaluate('//div[@id=\'bodyContent\']//a[@name]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); anchorCount = xp_anchors.snapshotLength; curAnchor = -1; jumpDownEnabled = false; jumpDownStatus = document.createElement('span'); jumpDownStatus.setAttribute('style', 'padding:15px; background:#ddddff; border-left:1px solid #333388; border-top:1px solid #333388; font:8pt Verdana; color:#333388; position:fixed; right:0px; bottom:0px; width:300px; z-index:99; opacity:0;'); document.getElementsByTagName('body')[0].appendChild(jumpDownStatus); }

function getAnchorName(anchor) { var innerHead = anchor.nextSibling; if (innerHead.tagName.charAt(0) != 'H') return ''; return innerHead.textContent; }

function keyHandler(evt) { var src = evt.target.tagName.toUpperCase; if (src == 'INPUT' || src == 'TEXTAREA') return; if (evt.which == 106) { if (curAnchor < anchorCount - 1) curAnchor++; } else if (evt.which == 117) { if (curAnchor > 0) curAnchor--; } else if (evt.which == 116) { curAnchor = -1; } else { return; }   if (curAnchor == -1) { location.hash = 'top'; } else { location.hash = xp_anchors.snapshotItem(curAnchor).name; jumpDownStatus.innerHTML = "Current section: " + getAnchorName(xp_anchors.snapshotItem(curAnchor)) + ' ' + '' + 'j - move to the next section ' + 'u - move to the previous section ' + 't - back to top'; clearTimeout(faderTimer);

jumpDownStatus.style.opacity = 1.0; faderTimer = setTimeout(faderTimeout, 2000); } }

function faderTimeout { jumpDownStatus.style.opacity -= .05; if (jumpDownStatus.style.opacity <= 0) clearTimeout(faderTimer); faderTimer = setTimeout(faderTimeout, 50); }