forked from leftypol/leftypol
show-op.js: reduce queries
This commit is contained in:
parent
da3ad44f37
commit
4db387ab52
1 changed files with 13 additions and 15 deletions
|
@ -21,31 +21,29 @@ $(document).ready(function() {
|
|||
|
||||
let showOPLinks = function() {
|
||||
// Use the cached op if we're in a thread, otherwise fetch it.
|
||||
let localOp = threadPageOp ? threadPageOp : parseInt($(this).parent().find('div.post.op a.post_no:eq(1)').text());
|
||||
let localOp = threadPageOp ? threadPageOp : parseInt($(this).parent().parent().parent().find('div.post.op a.post_no:eq(1)').text());
|
||||
|
||||
$(this).find('div.body a:not([rel="nofollow"])').each(function() {
|
||||
let postID = $(this).text().match(/^>>(\d+)$/);
|
||||
let postID = $(this).text().match(/^>>(\d+)$/);
|
||||
|
||||
if (postID) {
|
||||
postID = parseInt(postID[1]);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (postID) {
|
||||
postID = parseInt(postID[1]);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (postID === localOp) {
|
||||
$(this).after(' <small>(OP)</small>');
|
||||
}
|
||||
});
|
||||
if (postID === localOp) {
|
||||
$(this).after(' <small>(OP)</small>');
|
||||
}
|
||||
};
|
||||
|
||||
$('div.post.reply').each(showOPLinks);
|
||||
$('div.post.reply > div.body a:not([rel="nofollow"])').each(showOPLinks);
|
||||
|
||||
// allow to work with auto-reload.js, etc.
|
||||
$(document).on('new_post', function(e, post) {
|
||||
if ($(post).is('div.post.reply')) {
|
||||
if ($(post).is('div.post.reply > div.body a:not([rel="nofollow"])')) {
|
||||
$(post).each(showOPLinks);
|
||||
} else {
|
||||
$(post).find('div.post.reply').each(showOPLinks);
|
||||
$(post).find('div.post.reply > div.body a:not([rel="nofollow"])').each(showOPLinks);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue