Restore Scroll To Post Quoting You functionality.

This commit is contained in:
Zixaphir 2014-03-24 13:29:09 -07:00
parent e20a822481
commit 148edd3e33
5 changed files with 137 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/*
* 4chan X - Version 1.4.1 - 2014-03-23
* 4chan X - Version 1.4.1 - 2014-03-24
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE

View File

@ -24,7 +24,7 @@
// ==/UserScript==
/*
* 4chan X - Version 1.4.1 - 2014-03-23
* 4chan X - Version 1.4.1 - 2014-03-24
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
@ -5501,6 +5501,50 @@
} else if (mayReset) {
return quotelink.textContent = text;
}
},
cb: {
seek: function(type) {
var post;
if (Conf['Mark Quotes of You'] && (post = QuotesYou.cb.findPost(type))) {
return Quotesyou.cb.scroll(post);
}
},
findPost: function(type) {
var i, index, len, post, posts;
posts = $$('.quotesYou');
if (!QuoteMarkers.lastRead) {
if (!(post = QuoteMarkers.lastRead = posts[0])) {
new Notice('warning', 'No posts are currently quoting you, loser.', 20);
return;
}
if (!Get.postFromRoot(post).isHidden) {
return post;
}
} else {
post = QuoteMarkers.lastRead;
}
len = posts.length - 1;
index = i = posts.indexOf(post);
while (true) {
if (index === (i = i === 0 ? len : i === len ? 0 : type === 'prev' ? i - 1 : i + 1)) {
break;
}
post = posts[i];
if (!Get.postFromRoot(post).isHidden) {
return post;
}
}
},
scroll: function(post) {
var highlight;
if (highlight = $('.highlight')) {
$.rmClass(highlight, 'highlight');
}
QuoteMarkers.lastRead = post;
window.location.hash = "#" + post.id;
Header.scrollTo(post);
return $.addClass($('.post', post), 'highlight');
}
}
};
@ -11962,10 +12006,10 @@
PostHiding.toggle(thread.OP);
break;
case Conf['Previous Post Quoting You']:
QuoteYou.cb.seek('preceding');
QuoteMarkers.cb.seek('preceding');
break;
case Conf['Next Post Quoting You']:
QuoteYou.cb.seek('following');
QuoteMarkers.cb.seek('following');
break;
default:
return;

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript
/*
* 4chan X - Version 1.4.1 - 2014-03-23
* 4chan X - Version 1.4.1 - 2014-03-24
*
* Licensed under the MIT license.
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
@ -5555,6 +5555,50 @@
} else if (mayReset) {
return quotelink.textContent = text;
}
},
cb: {
seek: function(type) {
var post;
if (Conf['Mark Quotes of You'] && (post = QuotesYou.cb.findPost(type))) {
return Quotesyou.cb.scroll(post);
}
},
findPost: function(type) {
var i, index, len, post, posts;
posts = $$('.quotesYou');
if (!QuoteMarkers.lastRead) {
if (!(post = QuoteMarkers.lastRead = posts[0])) {
new Notice('warning', 'No posts are currently quoting you, loser.', 20);
return;
}
if (!Get.postFromRoot(post).isHidden) {
return post;
}
} else {
post = QuoteMarkers.lastRead;
}
len = posts.length - 1;
index = i = posts.indexOf(post);
while (true) {
if (index === (i = i === 0 ? len : i === len ? 0 : type === 'prev' ? i - 1 : i + 1)) {
break;
}
post = posts[i];
if (!Get.postFromRoot(post).isHidden) {
return post;
}
}
},
scroll: function(post) {
var highlight;
if (highlight = $('.highlight')) {
$.rmClass(highlight, 'highlight');
}
QuoteMarkers.lastRead = post;
window.location.hash = "#" + post.id;
Header.scrollTo(post);
return $.addClass($('.post', post), 'highlight');
}
}
};
@ -11978,10 +12022,10 @@
PostHiding.toggle(thread.OP);
break;
case Conf['Previous Post Quoting You']:
QuoteYou.cb.seek('preceding');
QuoteMarkers.cb.seek('preceding');
break;
case Conf['Next Post Quoting You']:
QuoteYou.cb.seek('following');
QuoteMarkers.cb.seek('following');
break;
default:
return;

View File

@ -135,9 +135,9 @@ Keybinds =
when Conf['Hide']
PostHiding.toggle thread.OP
when Conf['Previous Post Quoting You']
QuoteYou.cb.seek 'preceding'
QuoteMarkers.cb.seek 'preceding'
when Conf['Next Post Quoting You']
QuoteYou.cb.seek 'following'
QuoteMarkers.cb.seek 'following'
else
return
e.preventDefault()

View File

@ -45,3 +45,43 @@ QuoteMarkers =
quotelink.textContent = "#{text}\u00A0(#{markers.join '|'})"
else if mayReset
quotelink.textContent = text
cb:
seek: (type) ->
if Conf['Mark Quotes of You'] and post = QuotesYou.cb.findPost type
Quotesyou.cb.scroll post
findPost: (type) ->
posts = $$ '.quotesYou'
unless QuoteMarkers.lastRead
unless post = QuoteMarkers.lastRead = posts[0]
new Notice 'warning', 'No posts are currently quoting you, loser.', 20
return
unless Get.postFromRoot(post).isHidden
return post
else
post = QuoteMarkers.lastRead
len = posts.length - 1
index = i = posts.indexOf post
while true
break if index is (
i = if i is 0
len
else if i is len
0
else if type is 'prev'
i - 1
else
i + 1
)
post = posts[i]
return post unless Get.postFromRoot(post).isHidden
scroll: (post) ->
$.rmClass highlight, 'highlight' if highlight = $ '.highlight'
QuoteMarkers.lastRead = post
window.location.hash = "##{post.id}"
Header.scrollTo post
$.addClass $('.post', post), 'highlight'