File tree 1 file changed +22
-7
lines changed 1 file changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -305,6 +305,7 @@ function initLinkEvent() {
305
305
}
306
306
307
307
function initHoverEvent ( ) {
308
+ let timer : number | null = null
308
309
document . documentElement . addEventListener ( 'mouseover' , ( evt ) => {
309
310
const target = evt . target as HTMLElement
310
311
const link = target . closest ( 'a[href]' ) as HTMLAnchorElement | null
@@ -317,13 +318,27 @@ function initHoverEvent() {
317
318
if ( ! mainContent || ! mainContent . contains ( link ) ) return
318
319
319
320
if ( hoveredUrls . has ( link . href ) ) return // Otherwise this is a flood of events
320
- const sameSite = link . origin === location . origin
321
- hoveredUrls . add ( link . href )
322
- sendEvent ( {
323
- type : EventType . hover ,
324
- hover_url : link . href ,
325
- hover_samesite : sameSite ,
326
- } )
321
+
322
+ if ( timer ) {
323
+ window . clearTimeout ( timer )
324
+ }
325
+ timer = window . setTimeout ( ( ) => {
326
+ const sameSite = link . origin === location . origin
327
+ hoveredUrls . add ( link . href )
328
+ sendEvent ( {
329
+ type : EventType . hover ,
330
+ hover_url : link . href ,
331
+ hover_samesite : sameSite ,
332
+ } )
333
+ } , 500 )
334
+ } )
335
+
336
+ // Doesn't matter which link you hovered on that triggered a timer,
337
+ // you're clearly not hovering over it any more.
338
+ document . documentElement . addEventListener ( 'mouseout' , ( ) => {
339
+ if ( timer ) {
340
+ window . clearTimeout ( timer )
341
+ }
327
342
} )
328
343
}
329
344
You can’t perform that action at this time.
0 commit comments