Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repo sync #25526

Merged
merged 1 commit into from
May 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/events/components/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ function initLinkEvent() {
}

function initHoverEvent() {
let timer: number | null = null
document.documentElement.addEventListener('mouseover', (evt) => {
const target = evt.target as HTMLElement
const link = target.closest('a[href]') as HTMLAnchorElement | null
Expand All @@ -317,13 +318,27 @@ function initHoverEvent() {
if (!mainContent || !mainContent.contains(link)) return

if (hoveredUrls.has(link.href)) return // Otherwise this is a flood of events
const sameSite = link.origin === location.origin
hoveredUrls.add(link.href)
sendEvent({
type: EventType.hover,
hover_url: link.href,
hover_samesite: sameSite,
})

if (timer) {
window.clearTimeout(timer)
}
timer = window.setTimeout(() => {
const sameSite = link.origin === location.origin
hoveredUrls.add(link.href)
sendEvent({
type: EventType.hover,
hover_url: link.href,
hover_samesite: sameSite,
})
}, 500)
})

// Doesn't matter which link you hovered on that triggered a timer,
// you're clearly not hovering over it any more.
document.documentElement.addEventListener('mouseout', () => {
if (timer) {
window.clearTimeout(timer)
}
})
}

Expand Down