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); + }); }); }