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
This commit is contained in:
Ching L 2025-09-23 10:49:45 +08:00
parent e0b022d791
commit e04d4f447d

View File

@ -211,6 +211,7 @@
function setupClickListeners() { function setupClickListeners() {
// 监听所有帖子链接的点击 // 监听所有帖子链接的点击
document.querySelectorAll('a[href*="/archives/"]').forEach(link => { document.querySelectorAll('a[href*="/archives/"]').forEach(link => {
// 处理普通左键点击
link.addEventListener('click', function() { link.addEventListener('click', function() {
const match = this.href.match(/\/archives\/(\d+)\//); const match = this.href.match(/\/archives\/(\d+)\//);
if (match) { 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);
});
}); });
} }