Keybind to scroll to posts quoting you.

This commit is contained in:
Zixaphir 2013-08-08 23:53:48 -07:00
parent 191dc4911f
commit 6ba8d9ae8c
7 changed files with 137 additions and 7 deletions

View File

@ -297,7 +297,9 @@
'Next reply': ['j', 'Select next reply.'],
'Previous reply': ['k', 'Select previous reply.'],
'Deselect reply': ['Shift+d', 'Deselect reply.'],
'Hide': ['x', 'Hide thread.']
'Hide': ['x', 'Hide thread.'],
'Previous Post Quoting You': ['Alt+Up', 'Scroll to the previous post that quotes you.'],
'Next Post Quoting You': ['Alt+Down', 'Scroll to the next post that quotes you.']
},
updater: {
checkbox: {
@ -4196,6 +4198,38 @@
$.addClass(this.nodes.root, 'quotesYou');
}
}
},
cb: {
seek: function(type) {
var post, posts, result, str;
if (!QuoteYou.lastRead) {
if (!(post = QuoteYou.lastRead = $('.quotesYou'))) {
new Notification('warning', 'No posts are currently quoting you, loser.', 20);
}
if (QuoteYou.cb.scroll(post)) {
return;
}
}
str = "" + type + "::div[contains(@class,'quotesYou')]";
result = $.X(str, QuoteYou.lastRead);
while (post = result.snapshotItem(type === 'preceding' ? result.snapshotLength - 1 : 0)) {
if (QuoteYou.cb.scroll(post)) {
return;
}
}
posts = $$('.quotesYou');
return QuoteYou.cb.scroll(posts[type === 'following' ? 0 : posts.length - 1]);
},
scroll: function(post) {
QuoteYou.lastRead = post;
if (Get.postFromRoot(post).isHidden) {
return false;
} else {
Header.scrollToPost(post);
return true;
}
}
}
};
@ -7971,6 +8005,11 @@
bottom = post.nodes.root.getBoundingClientRect().bottom;
if (bottom < height) {
ID = post.ID;
if (Conf['Mark Quotes of You']) {
if (post.info.yours) {
QuoteYou.lastRead = post.nodes.root;
}
}
if (Conf['Quote Threading']) {
posts.splice(i, 1);
continue;
@ -9091,6 +9130,12 @@
ThreadHiding.toggle(thread);
}
break;
case Conf['Previous Post Quoting You']:
QuoteYou.cb.seek('preceding');
break;
case Conf['Next Post Quoting You']:
QuoteYou.cb.seek('following');
break;
default:
return;
}

View File

@ -278,7 +278,9 @@
'Next reply': ['j', 'Select next reply.'],
'Previous reply': ['k', 'Select previous reply.'],
'Deselect reply': ['Shift+d', 'Deselect reply.'],
'Hide': ['x', 'Hide thread.']
'Hide': ['x', 'Hide thread.'],
'Previous Post Quoting You': ['Alt+Up', 'Scroll to the previous post that quotes you.'],
'Next Post Quoting You': ['Alt+Down', 'Scroll to the next post that quotes you.']
},
updater: {
checkbox: {
@ -4201,6 +4203,38 @@
$.addClass(this.nodes.root, 'quotesYou');
}
}
},
cb: {
seek: function(type) {
var post, posts, result, str;
if (!QuoteYou.lastRead) {
if (!(post = QuoteYou.lastRead = $('.quotesYou'))) {
new Notification('warning', 'No posts are currently quoting you, loser.', 20);
}
if (QuoteYou.cb.scroll(post)) {
return;
}
}
str = "" + type + "::div[contains(@class,'quotesYou')]";
result = $.X(str, QuoteYou.lastRead);
while (post = result.snapshotItem(type === 'preceding' ? result.snapshotLength - 1 : 0)) {
if (QuoteYou.cb.scroll(post)) {
return;
}
}
posts = $$('.quotesYou');
return QuoteYou.cb.scroll(posts[type === 'following' ? 0 : posts.length - 1]);
},
scroll: function(post) {
QuoteYou.lastRead = post;
if (Get.postFromRoot(post).isHidden) {
return false;
} else {
Header.scrollToPost(post);
return true;
}
}
}
};
@ -7952,6 +7986,11 @@
bottom = post.nodes.root.getBoundingClientRect().bottom;
if (bottom < height) {
ID = post.ID;
if (Conf['Mark Quotes of You']) {
if (post.info.yours) {
QuoteYou.lastRead = post.nodes.root;
}
}
if (Conf['Quote Threading']) {
posts.splice(i, 1);
continue;
@ -9077,6 +9116,12 @@
ThreadHiding.toggle(thread);
}
break;
case Conf['Previous Post Quoting You']:
QuoteYou.cb.seek('preceding');
break;
case Conf['Next Post Quoting You']:
QuoteYou.cb.seek('following');
break;
default:
return;
}

View File

@ -641,6 +641,14 @@ q-replace
'x'
'Hide thread.'
]
'Previous Post Quoting You': [
'Alt+Up'
'Scroll to the previous post that quotes you.'
]
'Next Post Quoting You': [
'Alt+Down'
'Scroll to the next post that quotes you.'
]
updater:
checkbox:

View File

@ -115,6 +115,10 @@ Keybinds =
Keybinds.hl 0, threadRoot
when Conf['Hide']
ThreadHiding.toggle thread if g.VIEW is 'index'
when Conf['Previous Post Quoting You']
QuoteYou.cb.seek 'preceding'
when Conf['Next Post Quoting You']
QuoteYou.cb.seek 'following'
else
return
e.preventDefault()

View File

@ -126,6 +126,9 @@ Unread =
{bottom} = post.nodes.root.getBoundingClientRect()
if bottom < height # post is completely read
{ID} = post
if Conf['Mark Quotes of You']
if post.info.yours
QuoteYou.lastRead = post.nodes.root
if Conf['Quote Threading']
posts.splice i, 1
continue

View File

@ -14,6 +14,7 @@ QuoteYou =
Post::callbacks.push
name: 'Mark Quotes of You'
cb: @node
node: ->
# Stop there if it's a clone.
return if @isClone
@ -29,3 +30,27 @@ QuoteYou =
$.add quotelink, $.tn '\u00A0(You)'
$.addClass @nodes.root, 'quotesYou'
return
cb:
seek: (type) ->
unless QuoteYou.lastRead
unless post = QuoteYou.lastRead = $ '.quotesYou'
new Notification 'warning', 'No posts are currently quoting you, loser.', 20
return if QuoteYou.cb.scroll post
str = "#{type}::div[contains(@class,'quotesYou')]"
result = $.X(str, QuoteYou.lastRead)
while post = result.snapshotItem(if type is 'preceding' then result.snapshotLength - 1 else 0)
return if QuoteYou.cb.scroll post
posts = $$ '.quotesYou'
QuoteYou.cb.scroll posts[if type is 'following' then 0 else posts.length - 1]
scroll: (post) ->
QuoteYou.lastRead = post
if Get.postFromRoot(post).isHidden
return false
else
Header.scrollToPost post
return true