show-op.js: reduce queries

This commit is contained in:
Zankaria 2024-08-21 12:51:57 +02:00
parent da3ad44f37
commit 4db387ab52

View file

@ -21,31 +21,29 @@ $(document).ready(function() {
let showOPLinks = function() { let showOPLinks = function() {
// Use the cached op if we're in a thread, otherwise fetch it. // 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) { if (postID) {
postID = parseInt(postID[1]); postID = parseInt(postID[1]);
} else { } else {
return; return;
} }
if (postID === localOp) { if (postID === localOp) {
$(this).after(' <small>(OP)</small>'); $(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. // allow to work with auto-reload.js, etc.
$(document).on('new_post', function(e, post) { $(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); $(post).each(showOPLinks);
} else { } else {
$(post).find('div.post.reply').each(showOPLinks); $(post).find('div.post.reply > div.body a:not([rel="nofollow"])').each(showOPLinks);
} }
}); });
}); });