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:
parent
e0b022d791
commit
e04d4f447d
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user