From da3ad44f37a5ab44c10845a15c37a6255ff2ed13 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 21 Aug 2024 12:37:23 +0200 Subject: [PATCH] show-op.js: cache the op id in thread pages --- js/show-op.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/js/show-op.js b/js/show-op.js index 14dfe467..161e76e4 100644 --- a/js/show-op.js +++ b/js/show-op.js @@ -14,25 +14,25 @@ */ $(document).ready(function() { - let showOPLinks = function() { - let OP; + let threadPageOp; + if (active_page === "thread") { + threadPageOp = parseInt($('div.post.op a.post_no:eq(1)').text()); + } - if ($('div.banner').length == 0) { - OP = parseInt($(this).parent().find('div.post.op a.post_no:eq(1)').text()); - } else { - OP = parseInt($('div.post.op a.post_no:eq(1)').text()); - } + 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()); $(this).find('div.body a:not([rel="nofollow"])').each(function() { let postID = $(this).text().match(/^>>(\d+)$/); if (postID) { - postID = postID[1]; + postID = parseInt(postID[1]); } else { return; } - if (postID == OP) { + if (postID === localOp) { $(this).after(' (OP)'); } });