From 4db387ab5282f0025c3f93a4ff12f5b4aa7e9efa Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 21 Aug 2024 12:51:57 +0200 Subject: [PATCH] show-op.js: reduce queries --- js/show-op.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/js/show-op.js b/js/show-op.js index 161e76e4..6f3bc850 100644 --- a/js/show-op.js +++ b/js/show-op.js @@ -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(' (OP)'); - } - }); + if (postID === localOp) { + $(this).after(' (OP)'); + } }; - $('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); } }); });