rearrange code, keybinds

j/k = down/up in reply and not reply
n/N = next / previous in not reply
This commit is contained in:
James Campos 2010-12-19 03:30:34 -08:00
parent f4327d3b19
commit 304c518a68
2 changed files with 179 additions and 226 deletions

View File

@ -466,63 +466,17 @@ keyModeNormal = (e) ->
window.scrollTo 0, 0 window.scrollTo 0, 0
location.hash = '' location.hash = ''
count or= 1 count or= 1
if g.REPLY
switch char
when "I"
unless qrLink = $ 'td.replyhl span[id] a:not(:first-child)'
qrLink = $ "span[id^=nothread] a:not(:first-child)"
if e.shiftKey
quickReply qrLink
else
quickReply qrLink, qrText qrLink
when "J"
if e.shiftKey
if td = $ 'td.replyhl'
td.className = 'reply'
rect = td.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #you're visible
next = x 'following::td[@class="reply"]', td
rect = next.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the next
next.className = 'replyhl'
return
replies = $$ 'td.reply'
for reply in replies
top = reply.getBoundingClientRect().top
if top > 0
reply.className = 'replyhl'
break
else
window.scrollBy 0, 20 * count
when "K"
if e.shiftKey
if td = $ 'td.replyhl'
td.className = 'reply'
rect = td.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #you're visible
prev = x 'preceding::td[@class="reply"][1]', td
rect = prev.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the prev
prev.className = 'replyhl'
return
replies = $$ 'td.reply'
replies.reverse()
height = d.body.clientHeight
for reply in replies
bot = reply.getBoundingClientRect().bottom
if bot < height
reply.className = 'replyhl'
break
else
window.scrollBy 0, -20 * count
else
switch char switch char
when "H" when "H"
unless g.REPLY
temp = g.PAGENUM - count temp = g.PAGENUM - count
if temp < 0 then temp = 0 if temp < 0 then temp = 0
location.pathname = "/#{g.BOARD}/#{temp}#1" location.pathname = "/#{g.BOARD}/#{temp}#1"
when "I" when "I"
#TODO scroll when replying to op if g.reply
unless qrLink = $ 'td.replyhl span[id] a:not(:first-child)'
qrLink = $ "span[id^=nothread] a:not(:first-child)"
else
[thread] = getThread() [thread] = getThread()
unless qrLink = $ 'td.replyhl span[id] a:not(:first-child)', thread unless qrLink = $ 'td.replyhl span[id] a:not(:first-child)', thread
qrLink = $ "span#nothread#{thread.id} a:not(:first-child)", thread qrLink = $ "span#nothread#{thread.id} a:not(:first-child)", thread
@ -532,29 +486,48 @@ keyModeNormal = (e) ->
quickReply qrLink, qrText qrLink quickReply qrLink, qrText qrLink
when "J" when "J"
if e.shiftKey if e.shiftKey
[thread] = getThread() if not g.REPLY then [root] = getThread()
replies = $$ 'td[id]', thread if td = $ 'td.replyhl', root
for reply, i in replies td.className = 'reply'
if reply.className is 'replyhl' rect = td.getBoundingClientRect()
reply.className = 'reply' if rect.top > 0 and rect.bottom < d.body.clientHeight #you're visible
replies[i+1]?.className = 'replyhl' next = x 'following::td[@class="reply"]', td
rect = next.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the next
next.className = 'replyhl'
return return
replies[0].className = 'replyhl' replies = $$ 'td.reply', root
for reply in replies
top = reply.getBoundingClientRect().top
if top > 0
reply.className = 'replyhl'
break
else else
scroll count window.scrollBy 0, 20 * count
when "K" when "K"
if e.shiftKey if e.shiftKey
[thread] = getThread() if not g.REPLY then [root] = getThread()
replies = $$ 'td[id]', thread if td = $ 'td.replyhl', root
for reply, i in replies td.className = 'reply'
if reply.className is 'replyhl' rect = td.getBoundingClientRect()
reply.className = 'reply' if rect.top > 0 and rect.bottom < d.body.clientHeight #you're visible
replies[i-1]?.className = 'replyhl' prev = x 'preceding::td[@class="reply"][1]', td
rect = prev.getBoundingClientRect()
if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the prev
prev.className = 'replyhl'
return return
replies.pop().className = 'replyhl' replies = $$ 'td.reply', root
replies.reverse()
height = d.body.clientHeight
for reply in replies
bot = reply.getBoundingClientRect().bottom
if bot < height
reply.className = 'replyhl'
break
else else
scroll count * -1 window.scrollBy 0, -20 * count
when "L" when "L"
unless g.REPLY
temp = g.PAGENUM + count temp = g.PAGENUM + count
if temp > 15 then temp = 15 if temp > 15 then temp = 15
location.pathname = "/#{g.BOARD}/#{temp}#0" location.pathname = "/#{g.BOARD}/#{temp}#0"
@ -562,12 +535,18 @@ keyModeNormal = (e) ->
if e.shiftKey if e.shiftKey
$("#imageExpand").click() $("#imageExpand").click()
else else
[thread] = getThread() if not g.REPLY then [root] = getThread()
unless image = $ 'td.replyhl span.filesize ~ a[target]', thread unless image = $ 'td.replyhl span.filesize ~ a[target]', root
image = $ 'span.filesize ~ a[target]', thread image = $ 'span.filesize ~ a[target]', root
imageToggle image imageToggle image
when "N"
sign = if e.shiftKey then -1 else 1
scroll sign * count
when "O" when "O"
href = $("#{hash} ~ span[id] a:last-of-type").href href = $("#{hash} ~ span[id] a:last-of-type").href
if e.shiftKey
location.href = href
else
GM_openInTab href GM_openInTab href
when "W" when "W"
watchButton = $("#{hash} ~ img") watchButton = $("#{hash} ~ img")

View File

@ -560,7 +560,7 @@
} }
}; };
keyModeNormal = function(e) { keyModeNormal = function(e) {
var bot, char, count, hash, height, href, i, image, next, prev, qrLink, rect, replies, reply, td, temp, thread, top, watchButton, _i, _j, _len, _len2, _len3, _len4, _ref, _ref2; var bot, char, count, hash, height, href, image, next, prev, qrLink, rect, replies, reply, root, sign, td, temp, thread, top, watchButton, _i, _j, _len, _len2;
if (e.ctrlKey || e.altKey) { if (e.ctrlKey || e.altKey) {
return; return;
} }
@ -591,12 +591,27 @@
} }
} }
count || (count = 1); count || (count = 1);
if (g.REPLY) {
switch (char) { switch (char) {
case "H":
if (!g.REPLY) {
temp = g.PAGENUM - count;
if (temp < 0) {
temp = 0;
}
return location.pathname = "/" + g.BOARD + "/" + temp + "#1";
}
break;
case "I": case "I":
if (g.reply) {
if (!(qrLink = $('td.replyhl span[id] a:not(:first-child)'))) { if (!(qrLink = $('td.replyhl span[id] a:not(:first-child)'))) {
qrLink = $("span[id^=nothread] a:not(:first-child)"); qrLink = $("span[id^=nothread] a:not(:first-child)");
} }
} else {
thread = getThread()[0];
if (!(qrLink = $('td.replyhl span[id] a:not(:first-child)', thread))) {
qrLink = $("span#nothread" + thread.id + " a:not(:first-child)", thread);
}
}
if (e.shiftKey) { if (e.shiftKey) {
return quickReply(qrLink); return quickReply(qrLink);
} else { } else {
@ -605,7 +620,10 @@
break; break;
case "J": case "J":
if (e.shiftKey) { if (e.shiftKey) {
if (td = $('td.replyhl')) { if (!g.REPLY) {
root = getThread()[0];
}
if (td = $('td.replyhl', root)) {
td.className = 'reply'; td.className = 'reply';
rect = td.getBoundingClientRect(); rect = td.getBoundingClientRect();
if (rect.top > 0 && rect.bottom < d.body.clientHeight) { if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
@ -617,7 +635,7 @@
return; return;
} }
} }
replies = $$('td.reply'); replies = $$('td.reply', root);
for (_i = 0, _len = replies.length; _i < _len; _i++) { for (_i = 0, _len = replies.length; _i < _len; _i++) {
reply = replies[_i]; reply = replies[_i];
top = reply.getBoundingClientRect().top; top = reply.getBoundingClientRect().top;
@ -632,7 +650,10 @@
break; break;
case "K": case "K":
if (e.shiftKey) { if (e.shiftKey) {
if (td = $('td.replyhl')) { if (!g.REPLY) {
root = getThread()[0];
}
if (td = $('td.replyhl', root)) {
td.className = 'reply'; td.className = 'reply';
rect = td.getBoundingClientRect(); rect = td.getBoundingClientRect();
if (rect.top > 0 && rect.bottom < d.body.clientHeight) { if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
@ -644,7 +665,7 @@
return; return;
} }
} }
replies = $$('td.reply'); replies = $$('td.reply', root);
replies.reverse(); replies.reverse();
height = d.body.clientHeight; height = d.body.clientHeight;
for (_j = 0, _len2 = replies.length; _j < _len2; _j++) { for (_j = 0, _len2 = replies.length; _j < _len2; _j++) {
@ -658,92 +679,45 @@
} else { } else {
return window.scrollBy(0, -20 * count); return window.scrollBy(0, -20 * count);
} }
}
} else {
switch (char) {
case "H":
temp = g.PAGENUM - count;
if (temp < 0) {
temp = 0;
}
return location.pathname = "/" + g.BOARD + "/" + temp + "#1";
break;
case "I":
thread = getThread()[0];
if (!(qrLink = $('td.replyhl span[id] a:not(:first-child)', thread))) {
qrLink = $("span#nothread" + thread.id + " a:not(:first-child)", thread);
}
if (e.shiftKey) {
return quickReply(qrLink);
} else {
return quickReply(qrLink, qrText(qrLink));
}
break;
case "J":
if (e.shiftKey) {
thread = getThread()[0];
replies = $$('td[id]', thread);
for (i = 0, _len3 = replies.length; i < _len3; i++) {
reply = replies[i];
if (reply.className === 'replyhl') {
reply.className = 'reply';
if ((_ref = replies[i + 1]) != null) {
_ref.className = 'replyhl';
}
return;
}
}
return replies[0].className = 'replyhl';
} else {
return scroll(count);
}
break;
case "K":
if (e.shiftKey) {
thread = getThread()[0];
replies = $$('td[id]', thread);
for (i = 0, _len4 = replies.length; i < _len4; i++) {
reply = replies[i];
if (reply.className === 'replyhl') {
reply.className = 'reply';
if ((_ref2 = replies[i - 1]) != null) {
_ref2.className = 'replyhl';
}
return;
}
}
return replies.pop().className = 'replyhl';
} else {
return scroll(count * -1);
}
break; break;
case "L": case "L":
if (!g.REPLY) {
temp = g.PAGENUM + count; temp = g.PAGENUM + count;
if (temp > 15) { if (temp > 15) {
temp = 15; temp = 15;
} }
return location.pathname = "/" + g.BOARD + "/" + temp + "#0"; return location.pathname = "/" + g.BOARD + "/" + temp + "#0";
}
break; break;
case "M": case "M":
if (e.shiftKey) { if (e.shiftKey) {
return $("#imageExpand").click(); return $("#imageExpand").click();
} else { } else {
thread = getThread()[0]; if (!g.REPLY) {
if (!(image = $('td.replyhl span.filesize ~ a[target]', thread))) { root = getThread()[0];
image = $('span.filesize ~ a[target]', thread); }
if (!(image = $('td.replyhl span.filesize ~ a[target]', root))) {
image = $('span.filesize ~ a[target]', root);
} }
return imageToggle(image); return imageToggle(image);
} }
break; break;
case "N":
sign = e.shiftKey ? -1 : 1;
return scroll(sign * count);
break;
case "O": case "O":
href = $("" + hash + " ~ span[id] a:last-of-type").href; href = $("" + hash + " ~ span[id] a:last-of-type").href;
if (e.shiftKey) {
return location.href = href;
} else {
return GM_openInTab(href); return GM_openInTab(href);
}
break; break;
case "W": case "W":
watchButton = $("" + hash + " ~ img"); watchButton = $("" + hash + " ~ img");
return watch.call(watchButton); return watch.call(watchButton);
} }
}
}; };
nodeInserted = function(e) { nodeInserted = function(e) {
var callback, qr, target, _i, _len, _ref, _results; var callback, qr, target, _i, _len, _ref, _results;