keyboard navigation

idea stolen from http://userscripts.org/scripts/show/90085
This commit is contained in:
James Campos 2010-11-11 19:20:35 -08:00
parent 5acdf0df46
commit a25aea2a81
2 changed files with 47 additions and 2 deletions

View File

@ -11,6 +11,7 @@ config =
'Reply Hiding': [true, 'Hide single replies'] 'Reply Hiding': [true, 'Hide single replies']
'Show Stubs': [true, 'Of hidden threads / replies'] 'Show Stubs': [true, 'Of hidden threads / replies']
'Thread Navigation': [true, 'Navigate to previous / next thread'] 'Thread Navigation': [true, 'Navigate to previous / next thread']
'Keyboard Navigation': [true, 'Navigate threads w/ your keyboard']
'Reply Navigation': [true, 'Navigate to the beginning / end of a thread'] 'Reply Navigation': [true, 'Navigate to the beginning / end of a thread']
'Thread Watcher': [true, 'Bookmark threads'] 'Thread Watcher': [true, 'Bookmark threads']
'Thread Expansion': [true, 'View all replies'] 'Thread Expansion': [true, 'View all replies']
@ -354,6 +355,27 @@ iframeLoad = ->
remove qr remove qr
recaptchaReload() recaptchaReload()
keyboardNav = (e) ->
hash = Number(location.hash?.substring(1)) or 0
switch e.keyCode
when 71 #g
if e.shiftKey
location.hash = 'navbot'
else
location.hash = 'navtop'
when 72 #h
if g.PAGENUM > 0
location.pathname = "/#{g.BOARD}/#{g.PAGENUM - 1}#1"
when 74 #j
if hash < 10
location.hash = hash + 1
when 75 #k
if hash > 0
location.hash = hash - 1 or 'navtop'
when 76 #l
if g.PAGENUM < 15
location.pathname = "/#{g.BOARD}/#{g.PAGENUM + 1}#1"
nodeInserted = (e) -> nodeInserted = (e) ->
target = e.target target = e.target
if target.nodeName is 'TABLE' if target.nodeName is 'TABLE'
@ -872,7 +894,10 @@ if g.REPLY
if text if text
d.title = "/#{g.BOARD}/ - #{text}" d.title = "/#{g.BOARD}/ - #{text}"
else else #not reply
if getConfig 'Keyboard Navigation'
d.addEventListener 'keydown', keyboardNav, true
if getConfig 'Thread Hiding' if getConfig 'Thread Hiding'
delform = $('form[name=delform]') delform = $('form[name=delform]')
#don't confuse other scripts #don't confuse other scripts

View File

@ -1,11 +1,12 @@
(function() { (function() {
var $, $$, AEOS, DAY, _, _i, _len, _ref, _ref2, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, close, config, cooldown, cutoff, d, delform, down, editSauce, el, expandComment, expandThread, formSubmit, g, getConfig, getTime, hide, hideReply, hideThread, href, html, i, i1, id, iframe, iframeLoad, inAfter, inBefore, inputs, l, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, show, showReply, showThread, slice, span, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, up, watch, watchX, watcher, watcherUpdate, x; var $, $$, AEOS, DAY, _, _i, _len, _ref, _ref2, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, close, config, cooldown, cutoff, d, delform, down, editSauce, el, expandComment, expandThread, formSubmit, g, getConfig, getTime, hide, hideReply, hideThread, href, html, i, i1, id, iframe, iframeLoad, inAfter, inBefore, inputs, keyboardNav, l, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, show, showReply, showThread, slice, span, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, up, watch, watchX, watcher, watcherUpdate, x;
var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty; var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
config = { config = {
'Thread Hiding': [true, 'Hide entire threads'], 'Thread Hiding': [true, 'Hide entire threads'],
'Reply Hiding': [true, 'Hide single replies'], 'Reply Hiding': [true, 'Hide single replies'],
'Show Stubs': [true, 'Of hidden threads / replies'], 'Show Stubs': [true, 'Of hidden threads / replies'],
'Thread Navigation': [true, 'Navigate to previous / next thread'], 'Thread Navigation': [true, 'Navigate to previous / next thread'],
'Keyboard Navigation': [true, 'Navigate threads w/ your keyboard'],
'Reply Navigation': [true, 'Navigate to the beginning / end of a thread'], 'Reply Navigation': [true, 'Navigate to the beginning / end of a thread'],
'Thread Watcher': [true, 'Bookmark threads'], 'Thread Watcher': [true, 'Bookmark threads'],
'Thread Expansion': [true, 'View all replies'], 'Thread Expansion': [true, 'View all replies'],
@ -439,6 +440,22 @@
} }
return recaptchaReload(); return recaptchaReload();
}; };
keyboardNav = function(e) {
var hash;
hash = Number(location.hash == null ? undefined : location.hash.substring(1)) || 0;
switch (e.keyCode) {
case 71:
return e.shiftKey ? (location.hash = 'navbot') : (location.hash = 'navtop');
case 72:
return g.PAGENUM > 0 ? (location.pathname = ("/" + (g.BOARD) + "/" + (g.PAGENUM - 1) + "#1")) : null;
case 74:
return hash < 10 ? (location.hash = hash + 1) : null;
case 75:
return hash > 0 ? (location.hash = hash - 1 || 'navtop') : null;
case 76:
return g.PAGENUM < 15 ? (location.pathname = ("/" + (g.BOARD) + "/" + (g.PAGENUM + 1) + "#1")) : null;
}
};
nodeInserted = function(e) { nodeInserted = function(e) {
var _i, _len, _ref, _result, callback, qr, target; var _i, _len, _ref, _result, callback, qr, target;
target = e.target; target = e.target;
@ -1118,6 +1135,9 @@
} }
} }
} else { } else {
if (getConfig('Keyboard Navigation')) {
d.addEventListener('keydown', keyboardNav, true);
}
if (getConfig('Thread Hiding')) { if (getConfig('Thread Hiding')) {
delform = $('form[name=delform]'); delform = $('form[name=delform]');
d.addEventListener('DOMNodeInserted', stopPropagation, true); d.addEventListener('DOMNodeInserted', stopPropagation, true);