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
|
window.scrollTo 0, 0
|
||||||
location.hash = ''
|
location.hash = ''
|
||||||
count or= 1
|
count or= 1
|
||||||
if g.REPLY
|
switch char
|
||||||
switch char
|
when "H"
|
||||||
when "I"
|
unless g.REPLY
|
||||||
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"
|
|
||||||
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
|
||||||
if e.shiftKey
|
if e.shiftKey
|
||||||
quickReply qrLink
|
quickReply qrLink
|
||||||
else
|
else
|
||||||
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
|
||||||
return
|
rect = next.getBoundingClientRect()
|
||||||
replies[0].className = 'replyhl'
|
if rect.top > 0 and rect.bottom < d.body.clientHeight #and so is the next
|
||||||
else
|
next.className = 'replyhl'
|
||||||
scroll count
|
return
|
||||||
when "K"
|
replies = $$ 'td.reply', root
|
||||||
if e.shiftKey
|
for reply in replies
|
||||||
[thread] = getThread()
|
top = reply.getBoundingClientRect().top
|
||||||
replies = $$ 'td[id]', thread
|
if top > 0
|
||||||
for reply, i in replies
|
reply.className = 'replyhl'
|
||||||
if reply.className is 'replyhl'
|
break
|
||||||
reply.className = 'reply'
|
else
|
||||||
replies[i-1]?.className = 'replyhl'
|
window.scrollBy 0, 20 * count
|
||||||
return
|
when "K"
|
||||||
replies.pop().className = 'replyhl'
|
if e.shiftKey
|
||||||
else
|
if not g.REPLY then [root] = getThread()
|
||||||
scroll count * -1
|
if td = $ 'td.replyhl', root
|
||||||
when "L"
|
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
|
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"
|
||||||
when "M"
|
when "M"
|
||||||
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 "O"
|
when "N"
|
||||||
href = $("#{hash} ~ span[id] a:last-of-type").href
|
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
|
GM_openInTab href
|
||||||
when "W"
|
when "W"
|
||||||
watchButton = $("#{hash} ~ img")
|
watchButton = $("#{hash} ~ img")
|
||||||
watch.call watchButton
|
watch.call watchButton
|
||||||
|
|
||||||
nodeInserted = (e) ->
|
nodeInserted = (e) ->
|
||||||
target = e.target
|
target = e.target
|
||||||
|
|||||||
234
4chan_x.js
234
4chan_x.js
@ -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,158 +591,132 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
count || (count = 1);
|
count || (count = 1);
|
||||||
if (g.REPLY) {
|
switch (char) {
|
||||||
switch (char) {
|
case "H":
|
||||||
case "I":
|
if (!g.REPLY) {
|
||||||
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":
|
|
||||||
temp = g.PAGENUM - count;
|
temp = g.PAGENUM - count;
|
||||||
if (temp < 0) {
|
if (temp < 0) {
|
||||||
temp = 0;
|
temp = 0;
|
||||||
}
|
}
|
||||||
return location.pathname = "/" + g.BOARD + "/" + temp + "#1";
|
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];
|
thread = getThread()[0];
|
||||||
if (!(qrLink = $('td.replyhl span[id] a:not(:first-child)', thread))) {
|
if (!(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);
|
||||||
}
|
}
|
||||||
if (e.shiftKey) {
|
}
|
||||||
return quickReply(qrLink);
|
if (e.shiftKey) {
|
||||||
} else {
|
return quickReply(qrLink);
|
||||||
return quickReply(qrLink, qrText(qrLink));
|
} else {
|
||||||
|
return quickReply(qrLink, qrText(qrLink));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "J":
|
||||||
|
if (e.shiftKey) {
|
||||||
|
if (!g.REPLY) {
|
||||||
|
root = getThread()[0];
|
||||||
}
|
}
|
||||||
break;
|
if (td = $('td.replyhl', root)) {
|
||||||
case "J":
|
td.className = 'reply';
|
||||||
if (e.shiftKey) {
|
rect = td.getBoundingClientRect();
|
||||||
thread = getThread()[0];
|
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
|
||||||
replies = $$('td[id]', thread);
|
next = x('following::td[@class="reply"]', td);
|
||||||
for (i = 0, _len3 = replies.length; i < _len3; i++) {
|
rect = next.getBoundingClientRect();
|
||||||
reply = replies[i];
|
if (rect.top > 0 && rect.bottom < d.body.clientHeight) {
|
||||||
if (reply.className === 'replyhl') {
|
next.className = 'replyhl';
|
||||||
reply.className = 'reply';
|
|
||||||
if ((_ref = replies[i + 1]) != null) {
|
|
||||||
_ref.className = 'replyhl';
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return replies[0].className = 'replyhl';
|
|
||||||
} else {
|
|
||||||
return scroll(count);
|
|
||||||
}
|
}
|
||||||
break;
|
replies = $$('td.reply', root);
|
||||||
case "K":
|
for (_i = 0, _len = replies.length; _i < _len; _i++) {
|
||||||
if (e.shiftKey) {
|
reply = replies[_i];
|
||||||
thread = getThread()[0];
|
top = reply.getBoundingClientRect().top;
|
||||||
replies = $$('td[id]', thread);
|
if (top > 0) {
|
||||||
for (i = 0, _len4 = replies.length; i < _len4; i++) {
|
reply.className = 'replyhl';
|
||||||
reply = replies[i];
|
break;
|
||||||
if (reply.className === 'replyhl') {
|
}
|
||||||
reply.className = 'reply';
|
}
|
||||||
if ((_ref2 = replies[i - 1]) != null) {
|
} else {
|
||||||
_ref2.className = 'replyhl';
|
return window.scrollBy(0, 20 * count);
|
||||||
}
|
}
|
||||||
return;
|
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;
|
replies = $$('td.reply', root);
|
||||||
case "L":
|
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;
|
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;
|
}
|
||||||
case "M":
|
break;
|
||||||
if (e.shiftKey) {
|
case "M":
|
||||||
return $("#imageExpand").click();
|
if (e.shiftKey) {
|
||||||
} else {
|
return $("#imageExpand").click();
|
||||||
thread = getThread()[0];
|
} else {
|
||||||
if (!(image = $('td.replyhl span.filesize ~ a[target]', thread))) {
|
if (!g.REPLY) {
|
||||||
image = $('span.filesize ~ a[target]', thread);
|
root = getThread()[0];
|
||||||
}
|
|
||||||
return imageToggle(image);
|
|
||||||
}
|
}
|
||||||
break;
|
if (!(image = $('td.replyhl span.filesize ~ a[target]', root))) {
|
||||||
case "O":
|
image = $('span.filesize ~ a[target]', root);
|
||||||
href = $("" + hash + " ~ span[id] a:last-of-type").href;
|
}
|
||||||
|
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);
|
return GM_openInTab(href);
|
||||||
break;
|
}
|
||||||
case "W":
|
break;
|
||||||
watchButton = $("" + hash + " ~ img");
|
case "W":
|
||||||
return watch.call(watchButton);
|
watchButton = $("" + hash + " ~ img");
|
||||||
}
|
return watch.call(watchButton);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
nodeInserted = function(e) {
|
nodeInserted = function(e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user