use document.activeElement

This commit is contained in:
James Campos 2010-12-08 21:14:03 -08:00
parent 73edb76a6c
commit 35acc63d53
2 changed files with 37 additions and 88 deletions

View File

@ -203,7 +203,6 @@ autoWatch = ->
closeQR = -> closeQR = ->
div = this.parentNode.parentNode div = this.parentNode.parentNode
remove div remove div
keybindAdd()
clearHidden = -> clearHidden = ->
#'hidden' might be misleading; it's the number of IDs we're *looking* for, #'hidden' might be misleading; it's the number of IDs we're *looking* for,
@ -289,7 +288,6 @@ formSubmit = (e) ->
recaptcha = $('input[name=recaptcha_response_field]', this) recaptcha = $('input[name=recaptcha_response_field]', this)
if recaptcha.value if recaptcha.value
$('#qr input[title=autohide]:not(:checked)')?.click() $('#qr input[title=autohide]:not(:checked)')?.click()
keybindAdd()
else else
e.preventDefault() e.preventDefault()
span = n 'span', span = n 'span',
@ -355,7 +353,6 @@ iframeLoad = ->
className: 'error' className: 'error'
addTo qr, span addTo qr, span
$('input[title=autohide]:checked', qr)?.click() $('input[title=autohide]:checked', qr)?.click()
keybindRem()
else if g.REPLY and getConfig 'Persistent QR' else if g.REPLY and getConfig 'Persistent QR'
$('textarea', qr).value = '' $('textarea', qr).value = ''
$('input[name=recaptcha_response_field]', qr).value = '' $('input[name=recaptcha_response_field]', qr).value = ''
@ -371,20 +368,18 @@ iframeLoad = ->
remove qr remove qr
recaptchaReload() recaptchaReload()
keybindAdd = -> keydown = (e) ->
if getConfig 'Keybinds' if document.activeElement.nodeName in ['TEXTAREA', 'INPUT']
d.addEventListener 'keydown', keydown, true char = null
d.addEventListener 'keypress', keypress, true else if e.ctrlKey or e.altKey
char = null
keybindRem = -> else
d.removeEventListener 'keydown', keydown, true char = String.fromCharCode e.keyCode
d.removeEventListener 'keypress', keypress, true g.char = char
keypress = (e) -> keypress = (e) ->
kc = g.keyCode char = g.char
if kc is -1 then return return unless char
e.preventDefault()
char = String.fromCharCode kc
hash = location.hash hash = location.hash
count = g.count count = g.count
if char in '1234567890' if char in '1234567890'
@ -499,17 +494,6 @@ keypress = (e) ->
href = $("#{hash} ~ span[id] a:last-of-type").href href = $("#{hash} ~ span[id] a:last-of-type").href
GM_openInTab href GM_openInTab href
keydown = (e) ->
kc = e.keyCode
#https://developer.mozilla.org/en/DOM/Event/UIEvent/KeyEvent
# [0-9;=A-Z]
unless (48 <= kc <= 90)
g.keyCode = -1
else if e.ctrlKey or e.altKey
g.keyCode = -1
else
g.keyCode = kc
nodeInserted = (e) -> nodeInserted = (e) ->
target = e.target target = e.target
if target.nodeName is 'TABLE' if target.nodeName is 'TABLE'
@ -617,9 +601,6 @@ quickReply = (e) ->
target: 'iframe' target: 'iframe'
if getConfig 'Keybinds' if getConfig 'Keybinds'
inputs = $$ 'input[type=text], textarea', clone inputs = $$ 'input[type=text], textarea', clone
for input in inputs
input.addEventListener 'focus', keybindRem, true
input.addEventListener 'blur', keybindAdd, true
if not g.REPLY if not g.REPLY
#figure out which thread we're replying to #figure out which thread we're replying to
xpath = 'preceding::span[@class="postername"][1]/preceding::input[1]' xpath = 'preceding::span[@class="postername"][1]/preceding::input[1]'
@ -1075,12 +1056,8 @@ if getConfig 'Reply Navigation'
inAfter el, span inAfter el, span
if getConfig 'Keybinds' if getConfig 'Keybinds'
form = $ 'div.postarea > form' document.addEventListener 'keydown', keydown, true
inputs = $$ 'input[type=text], textarea', form document.addEventListener 'keypress', keypress, true
for input in inputs
input.addEventListener 'focus', keybindRem, true
input.addEventListener 'blur', keybindAdd, true
keybindAdd()
if g.REPLY if g.REPLY
if getConfig('Quick Reply') and getConfig 'Persistent QR' if getConfig('Quick Reply') and getConfig 'Persistent QR'

View File

@ -1,5 +1,5 @@
(function() { (function() {
var $, $$, AEOS, DAY, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expandComment, expandThread, form, formSubmit, g, getConfig, getThread, getTime, hide, hideReply, hideThread, href, html, i, id, iframe, iframeLoad, img, inAfter, inBefore, input, inputs, keybindAdd, keybindRem, keydown, keypress, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, scroll, show, showReply, showThread, slice, span, src, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, tzOffset, up, watch, watchX, watcher, watcherUpdate, x, zeroPad, _, _base, _fn, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _len7, _m, _n, _ref, _ref2, _ref3, _ref4; var $, $$, AEOS, DAY, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expandComment, expandThread, formSubmit, g, getConfig, getThread, getTime, hide, hideReply, hideThread, href, html, i, id, iframe, iframeLoad, img, inAfter, inBefore, input, inputs, keydown, keypress, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, scroll, show, showReply, showThread, slice, span, src, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, tzOffset, up, watch, watchX, watcher, watcherUpdate, x, zeroPad, _, _base, _fn, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _ref, _ref2, _ref3, _ref4;
var __slice = Array.prototype.slice, __indexOf = Array.prototype.indexOf || function(item) { var __slice = Array.prototype.slice, __indexOf = Array.prototype.indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) { for (var i = 0, l = this.length; i < l; i++) {
if (this[i] === item) return i; if (this[i] === item) return i;
@ -271,8 +271,7 @@
closeQR = function() { closeQR = function() {
var div; var div;
div = this.parentNode.parentNode; div = this.parentNode.parentNode;
remove(div); return remove(div);
return keybindAdd();
}; };
clearHidden = function() { clearHidden = function() {
GM_deleteValue("hiddenReplies/" + g.BOARD + "/"); GM_deleteValue("hiddenReplies/" + g.BOARD + "/");
@ -373,10 +372,7 @@
} }
recaptcha = $('input[name=recaptcha_response_field]', this); recaptcha = $('input[name=recaptcha_response_field]', this);
if (recaptcha.value) { if (recaptcha.value) {
if ((_ref = $('#qr input[title=autohide]:not(:checked)')) != null) { return (_ref = $('#qr input[title=autohide]:not(:checked)')) != null ? _ref.click() : void 0;
_ref.click();
}
return keybindAdd();
} else { } else {
e.preventDefault(); e.preventDefault();
span = n('span', { span = n('span', {
@ -458,7 +454,6 @@
if ((_ref = $('input[title=autohide]:checked', qr)) != null) { if ((_ref = $('input[title=autohide]:checked', qr)) != null) {
_ref.click(); _ref.click();
} }
keybindRem();
} else if (g.REPLY && getConfig('Persistent QR')) { } else if (g.REPLY && getConfig('Persistent QR')) {
$('textarea', qr).value = ''; $('textarea', qr).value = '';
$('input[name=recaptcha_response_field]', qr).value = ''; $('input[name=recaptcha_response_field]', qr).value = '';
@ -477,24 +472,23 @@
} }
return recaptchaReload(); return recaptchaReload();
}; };
keybindAdd = function() { keydown = function(e) {
if (getConfig('Keybinds')) { var char, _ref;
d.addEventListener('keydown', keydown, true); if ((_ref = document.activeElement.nodeName) === 'TEXTAREA' || _ref === 'INPUT') {
return d.addEventListener('keypress', keypress, true); char = null;
} else if (e.ctrlKey || e.altKey) {
char = null;
} else {
char = String.fromCharCode(e.keyCode);
} }
}; return g.char = char;
keybindRem = function() {
d.removeEventListener('keydown', keydown, true);
return d.removeEventListener('keypress', keypress, true);
}; };
keypress = function(e) { keypress = function(e) {
var bot, char, count, hash, height, href, i, img, kc, next, prev, qrLink, rect, replies, reply, td, temp, thread, top, _i, _j, _len, _len2, _len3, _len4, _ref, _ref2; var bot, char, count, hash, height, href, i, img, next, prev, qrLink, rect, replies, reply, td, temp, thread, top, _i, _j, _len, _len2, _len3, _len4, _ref, _ref2;
kc = g.keyCode; char = g.char;
if (kc === -1) { if (!char) {
return; return;
} }
e.preventDefault();
char = String.fromCharCode(kc);
hash = location.hash; hash = location.hash;
count = g.count; count = g.count;
if (__indexOf.call('1234567890', char) >= 0) { if (__indexOf.call('1234567890', char) >= 0) {
@ -656,17 +650,6 @@
} }
} }
}; };
keydown = function(e) {
var kc;
kc = e.keyCode;
if (!((48 <= kc && kc <= 90))) {
return g.keyCode = -1;
} else if (e.ctrlKey || e.altKey) {
return g.keyCode = -1;
} else {
return g.keyCode = kc;
}
};
nodeInserted = function(e) { nodeInserted = function(e) {
var callback, qr, target, _i, _len, _ref, _results; var callback, qr, target, _i, _len, _ref, _results;
target = e.target; target = e.target;
@ -772,7 +755,7 @@
return [replies, opbq]; return [replies, opbq];
}; };
quickReply = function(e) { quickReply = function(e) {
var auto, autoBox, autohideB, clone, closeB, form, id, input, inputs, qr, script, selection, submit, text, textarea, titlebar, xpath, _i, _j, _len, _len2, _ref, _ref2, _ref3; var auto, autoBox, autohideB, clone, closeB, form, id, input, inputs, qr, script, selection, submit, text, textarea, titlebar, xpath, _i, _len, _ref, _ref2, _ref3;
if (!(qr = $('#qr'))) { if (!(qr = $('#qr'))) {
qr = AEOS.makeDialog('qr', 'topleft'); qr = AEOS.makeDialog('qr', 'topleft');
titlebar = n('div', { titlebar = n('div', {
@ -810,11 +793,6 @@
}); });
if (getConfig('Keybinds')) { if (getConfig('Keybinds')) {
inputs = $$('input[type=text], textarea', clone); inputs = $$('input[type=text], textarea', clone);
for (_j = 0, _len2 = inputs.length; _j < _len2; _j++) {
input = inputs[_j];
input.addEventListener('focus', keybindRem, true);
input.addEventListener('blur', keybindAdd, true);
}
} }
if (!g.REPLY) { if (!g.REPLY) {
xpath = 'preceding::span[@class="postername"][1]/preceding::input[1]'; xpath = 'preceding::span[@class="postername"][1]/preceding::input[1]';
@ -1397,14 +1375,8 @@
}); });
} }
if (getConfig('Keybinds')) { if (getConfig('Keybinds')) {
form = $('div.postarea > form'); document.addEventListener('keydown', keydown, true);
inputs = $$('input[type=text], textarea', form); document.addEventListener('keypress', keypress, true);
for (_k = 0, _len3 = inputs.length; _k < _len3; _k++) {
input = inputs[_k];
input.addEventListener('focus', keybindRem, true);
input.addEventListener('blur', keybindAdd, true);
}
keybindAdd();
} }
if (g.REPLY) { if (g.REPLY) {
if (getConfig('Quick Reply') && getConfig('Persistent QR')) { if (getConfig('Quick Reply') && getConfig('Persistent QR')) {
@ -1432,7 +1404,7 @@
if (getConfig('Thread Navigation')) { if (getConfig('Thread Navigation')) {
arr = $$('div > span.filesize, form > span.filesize'); arr = $$('div > span.filesize, form > span.filesize');
l1 = arr.length - 1; l1 = arr.length - 1;
for (i = 0, _len4 = arr.length; i < _len4; i++) { for (i = 0, _len3 = arr.length; i < _len3; i++) {
el = arr[i]; el = arr[i];
span = n('span', { span = n('span', {
className: 'navlinks', className: 'navlinks',
@ -1474,8 +1446,8 @@
} }
if (getConfig('Thread Expansion')) { if (getConfig('Thread Expansion')) {
omitted = $$('span.omittedposts'); omitted = $$('span.omittedposts');
for (_l = 0, _len5 = omitted.length; _l < _len5; _l++) { for (_k = 0, _len4 = omitted.length; _k < _len4; _k++) {
span = omitted[_l]; span = omitted[_k];
a = n('a', { a = n('a', {
className: 'pointer omittedposts', className: 'pointer omittedposts',
textContent: "+ " + span.textContent, textContent: "+ " + span.textContent,
@ -1486,15 +1458,15 @@
} }
if (getConfig('Comment Expansion')) { if (getConfig('Comment Expansion')) {
as = $$('span.abbr a'); as = $$('span.abbr a');
for (_m = 0, _len6 = as.length; _m < _len6; _m++) { for (_l = 0, _len5 = as.length; _l < _len5; _l++) {
a = as[_m]; a = as[_l];
a.addEventListener('click', expandComment, true); a.addEventListener('click', expandComment, true);
} }
} }
} }
_ref4 = g.callbacks; _ref4 = g.callbacks;
for (_n = 0, _len7 = _ref4.length; _n < _len7; _n++) { for (_m = 0, _len6 = _ref4.length; _m < _len6; _m++) {
callback = _ref4[_n]; callback = _ref4[_m];
callback(); callback();
} }
d.body.addEventListener('DOMNodeInserted', nodeInserted, true); d.body.addEventListener('DOMNodeInserted', nodeInserted, true);