show-op.js: cache the op id in thread pages

This commit is contained in:
Zankaria 2024-08-21 12:37:23 +02:00
parent 4544107e1d
commit da3ad44f37

View file

@ -14,25 +14,25 @@
*/ */
$(document).ready(function() { $(document).ready(function() {
let showOPLinks = function() { let threadPageOp;
let OP; 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() { $(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 = postID[1]; postID = parseInt(postID[1]);
} else { } else {
return; return;
} }
if (postID == OP) { if (postID === localOp) {
$(this).after(' <small>(OP)</small>'); $(this).after(' <small>(OP)</small>');
} }
}); });