From e04d4f447d48d3bcfac8468ad577dc785745e506 Mon Sep 17 00:00:00 2001 From: Ching L Date: Tue, 23 Sep 2025 10:49:45 +0800 Subject: [PATCH] fix: track middle-click and context menu opens as visited - Added mousedown listener for middle-click (button 1) events - Added contextmenu listener for right-click menu actions - Ensures posts opened in new tabs are marked as visited --- 51cg-helper.user.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/51cg-helper.user.js b/51cg-helper.user.js index aa2774a..967b910 100644 --- a/51cg-helper.user.js +++ b/51cg-helper.user.js @@ -211,6 +211,7 @@ function setupClickListeners() { // 监听所有帖子链接的点击 document.querySelectorAll('a[href*="/archives/"]').forEach(link => { + // 处理普通左键点击 link.addEventListener('click', function() { const match = this.href.match(/\/archives\/(\d+)\//); if (match) { @@ -223,6 +224,40 @@ } } }); + + // 处理鼠标中键点击(新标签页打开) + link.addEventListener('mousedown', function(e) { + // 中键点击 (button === 1) + if (e.button === 1) { + const match = this.href.match(/\/archives\/(\d+)\//); + if (match) { + const postId = match[1]; + markPostAsVisited(postId); + // 立即应用样式 + const postCard = document.getElementById(`post-card-${postId}`); + if (postCard) { + postCard.classList.add('visited'); + } + } + } + }); + + // 处理右键菜单"在新标签页中打开" + link.addEventListener('contextmenu', function() { + // 延迟执行,让用户有机会选择菜单项 + setTimeout(() => { + const match = this.href.match(/\/archives\/(\d+)\//); + if (match) { + const postId = match[1]; + markPostAsVisited(postId); + // 立即应用样式 + const postCard = document.getElementById(`post-card-${postId}`); + if (postCard) { + postCard.classList.add('visited'); + } + } + }, 100); + }); }); }