rearrange code, keybinds
j/k = down/up in reply and not reply n/N = next / previous in not reply
This commit is contained in:
parent
f4327d3b19
commit
304c518a68
171
4chan_x.coffee
171
4chan_x.coffee
@ -466,112 +466,91 @@ keyModeNormal = (e) ->
|
||||
window.scrollTo 0, 0
|
||||
location.hash = ''
|
||||
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
|
||||
when "H"
|
||||
switch char
|
||||
when "H"
|
||||
unless g.REPLY
|
||||
temp = g.PAGENUM - count
|
||||
if temp < 0 then temp = 0
|
||||
location.pathname = "/#{g.BOARD}/#{temp}#1"
|
||||
when "I"
|
||||
#TODO scroll when replying to op
|
||||
when "I"
|
||||
if g.reply
|
||||
unless qrLink = $ 'td.replyhl span[id] a:not(:first-child)'
|
||||
qrLink = $ "span[id^=nothread] a:not(:first-child)"
|
||||
else
|
||||
[thread] = getThread()
|
||||
unless qrLink = $ 'td.replyhl span[id] a:not(:first-child)', thread
|
||||
qrLink = $ "span#nothread#{thread.id} a:not(:first-child)", thread
|
||||
if e.shiftKey
|
||||
quickReply qrLink
|
||||
else
|
||||
quickReply qrLink, qrText qrLink
|
||||
when "J"
|
||||
if e.shiftKey
|
||||
[thread] = getThread()
|
||||
replies = $$ 'td[id]', thread
|
||||
for reply, i in replies
|
||||
if reply.className is 'replyhl'
|
||||
reply.className = 'reply'
|
||||
replies[i+1]?.className = 'replyhl'
|
||||
return
|
||||
replies[0].className = 'replyhl'
|
||||
else
|
||||
scroll count
|
||||
when "K"
|
||||
if e.shiftKey
|
||||
[thread] = getThread()
|
||||
replies = $$ 'td[id]', thread
|
||||
for reply, i in replies
|
||||
if reply.className is 'replyhl'
|
||||
reply.className = 'reply'
|
||||
replies[i-1]?.className = 'replyhl'
|
||||
return
|
||||
replies.pop().className = 'replyhl'
|
||||
else
|
||||
scroll count * -1
|
||||
when "L"
|
||||
if e.shiftKey
|
||||
quickReply qrLink
|
||||
else
|
||||
quickReply qrLink, qrText qrLink
|
||||
when "J"
|
||||
if e.shiftKey
|
||||
if not g.REPLY then [root] = getThread()
|
||||
if td = $ 'td.replyhl', root
|
||||
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', root
|
||||
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 not g.REPLY then [root] = getThread()
|
||||
if td = $ 'td.replyhl', root
|
||||
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', root
|
||||
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
|
||||
when "L"
|
||||
unless g.REPLY
|
||||
temp = g.PAGENUM + count
|
||||
if temp > 15 then temp = 15
|
||||
location.pathname = "/#{g.BOARD}/#{temp}#0"
|
||||
when "M"
|
||||
if e.shiftKey
|
||||
$("#imageExpand").click()
|
||||
else
|
||||
[thread] = getThread()
|
||||
unless image = $ 'td.replyhl span.filesize ~ a[target]', thread
|
||||
image = $ 'span.filesize ~ a[target]', thread
|
||||
imageToggle image
|
||||
when "O"
|
||||
href = $("#{hash} ~ span[id] a:last-of-type").href
|
||||
when "M"
|
||||
if e.shiftKey
|
||||
$("#imageExpand").click()
|
||||
else
|
||||
if not g.REPLY then [root] = getThread()
|
||||
unless image = $ 'td.replyhl span.filesize ~ a[target]', root
|
||||
image = $ 'span.filesize ~ a[target]', root
|
||||
imageToggle image
|
||||
when "N"
|
||||
sign = if e.shiftKey then -1 else 1
|
||||
scroll sign * count
|
||||
when "O"
|
||||
href = $("#{hash} ~ span[id] a:last-of-type").href
|
||||
if e.shiftKey
|
||||
location.href = href
|
||||
else
|
||||
GM_openInTab href
|
||||
when "W"
|
||||
watchButton = $("#{hash} ~ img")
|
||||
watch.call watchButton
|
||||
when "W"
|
||||
watchButton = $("#{hash} ~ img")
|
||||
watch.call watchButton
|
||||
|
||||
nodeInserted = (e) ->
|
||||
target = e.target
|
||||
|
||||
234
4chan_x.js
234
4chan_x.js
@ -560,7 +560,7 @@
|
||||
}
|
||||
};
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@ -591,158 +591,132 @@
|
||||
}
|
||||
}
|
||||
count || (count = 1);
|
||||
if (g.REPLY) {
|
||||
switch (char) {
|
||||
case "I":
|
||||
if (!(qrLink = $('td.replyhl span[id] a:not(:first-child)'))) {
|
||||
qrLink = $("span[id^=nothread] a:not(:first-child)");
|
||||
}
|
||||
if (e.shiftKey) {
|
||||
return quickReply(qrLink);
|
||||
} else {
|
||||
return quickReply(qrLink, qrText(qrLink));
|
||||
}
|
||||
break;
|
||||
case "J":
|
||||
if (e.shiftKey) {
|
||||
if (td = $('td.replyhl')) {
|
||||
td.className = 'reply';
|
||||
rect = td.getBoundingClientRect();
|
||||
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
|
||||
next = x('following::td[@class="reply"]', td);
|
||||
rect = next.getBoundingClientRect();
|
||||
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
|
||||
next.className = 'replyhl';
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
replies = $$('td.reply');
|
||||
for (_i = 0, _len = replies.length; _i < _len; _i++) {
|
||||
reply = replies[_i];
|
||||
top = reply.getBoundingClientRect().top;
|
||||
if (top > 0) {
|
||||
reply.className = 'replyhl';
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return window.scrollBy(0, 20 * count);
|
||||
}
|
||||
break;
|
||||
case "K":
|
||||
if (e.shiftKey) {
|
||||
if (td = $('td.replyhl')) {
|
||||
td.className = 'reply';
|
||||
rect = td.getBoundingClientRect();
|
||||
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
|
||||
prev = x('preceding::td[@class="reply"][1]', td);
|
||||
rect = prev.getBoundingClientRect();
|
||||
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
|
||||
prev.className = 'replyhl';
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
replies = $$('td.reply');
|
||||
replies.reverse();
|
||||
height = d.body.clientHeight;
|
||||
for (_j = 0, _len2 = replies.length; _j < _len2; _j++) {
|
||||
reply = replies[_j];
|
||||
bot = reply.getBoundingClientRect().bottom;
|
||||
if (bot < height) {
|
||||
reply.className = 'replyhl';
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return window.scrollBy(0, -20 * count);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (char) {
|
||||
case "H":
|
||||
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":
|
||||
}
|
||||
break;
|
||||
case "I":
|
||||
if (g.reply) {
|
||||
if (!(qrLink = $('td.replyhl span[id] 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) {
|
||||
return quickReply(qrLink);
|
||||
} else {
|
||||
return quickReply(qrLink, qrText(qrLink));
|
||||
}
|
||||
if (e.shiftKey) {
|
||||
return quickReply(qrLink);
|
||||
} else {
|
||||
return quickReply(qrLink, qrText(qrLink));
|
||||
}
|
||||
break;
|
||||
case "J":
|
||||
if (e.shiftKey) {
|
||||
if (!g.REPLY) {
|
||||
root = getThread()[0];
|
||||
}
|
||||
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;
|
||||
if (td = $('td.replyhl', root)) {
|
||||
td.className = 'reply';
|
||||
rect = td.getBoundingClientRect();
|
||||
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
|
||||
next = x('following::td[@class="reply"]', td);
|
||||
rect = next.getBoundingClientRect();
|
||||
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
|
||||
next.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;
|
||||
replies = $$('td.reply', root);
|
||||
for (_i = 0, _len = replies.length; _i < _len; _i++) {
|
||||
reply = replies[_i];
|
||||
top = reply.getBoundingClientRect().top;
|
||||
if (top > 0) {
|
||||
reply.className = 'replyhl';
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return window.scrollBy(0, 20 * count);
|
||||
}
|
||||
break;
|
||||
case "K":
|
||||
if (e.shiftKey) {
|
||||
if (!g.REPLY) {
|
||||
root = getThread()[0];
|
||||
}
|
||||
if (td = $('td.replyhl', root)) {
|
||||
td.className = 'reply';
|
||||
rect = td.getBoundingClientRect();
|
||||
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
|
||||
prev = x('preceding::td[@class="reply"][1]', td);
|
||||
rect = prev.getBoundingClientRect();
|
||||
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
|
||||
prev.className = 'replyhl';
|
||||
}
|
||||
return;
|
||||
}
|
||||
return replies.pop().className = 'replyhl';
|
||||
} else {
|
||||
return scroll(count * -1);
|
||||
}
|
||||
break;
|
||||
case "L":
|
||||
replies = $$('td.reply', root);
|
||||
replies.reverse();
|
||||
height = d.body.clientHeight;
|
||||
for (_j = 0, _len2 = replies.length; _j < _len2; _j++) {
|
||||
reply = replies[_j];
|
||||
bot = reply.getBoundingClientRect().bottom;
|
||||
if (bot < height) {
|
||||
reply.className = 'replyhl';
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return window.scrollBy(0, -20 * count);
|
||||
}
|
||||
break;
|
||||
case "L":
|
||||
if (!g.REPLY) {
|
||||
temp = g.PAGENUM + count;
|
||||
if (temp > 15) {
|
||||
temp = 15;
|
||||
}
|
||||
return location.pathname = "/" + g.BOARD + "/" + temp + "#0";
|
||||
break;
|
||||
case "M":
|
||||
if (e.shiftKey) {
|
||||
return $("#imageExpand").click();
|
||||
} else {
|
||||
thread = getThread()[0];
|
||||
if (!(image = $('td.replyhl span.filesize ~ a[target]', thread))) {
|
||||
image = $('span.filesize ~ a[target]', thread);
|
||||
}
|
||||
return imageToggle(image);
|
||||
}
|
||||
break;
|
||||
case "M":
|
||||
if (e.shiftKey) {
|
||||
return $("#imageExpand").click();
|
||||
} else {
|
||||
if (!g.REPLY) {
|
||||
root = getThread()[0];
|
||||
}
|
||||
break;
|
||||
case "O":
|
||||
href = $("" + hash + " ~ span[id] a:last-of-type").href;
|
||||
if (!(image = $('td.replyhl span.filesize ~ a[target]', root))) {
|
||||
image = $('span.filesize ~ a[target]', root);
|
||||
}
|
||||
return imageToggle(image);
|
||||
}
|
||||
break;
|
||||
case "N":
|
||||
sign = e.shiftKey ? -1 : 1;
|
||||
return scroll(sign * count);
|
||||
break;
|
||||
case "O":
|
||||
href = $("" + hash + " ~ span[id] a:last-of-type").href;
|
||||
if (e.shiftKey) {
|
||||
return location.href = href;
|
||||
} else {
|
||||
return GM_openInTab(href);
|
||||
break;
|
||||
case "W":
|
||||
watchButton = $("" + hash + " ~ img");
|
||||
return watch.call(watchButton);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "W":
|
||||
watchButton = $("" + hash + " ~ img");
|
||||
return watch.call(watchButton);
|
||||
}
|
||||
};
|
||||
nodeInserted = function(e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user