@@ -361,7 +361,7 @@ class LinkHintsMode {
361
361
// We need documentElement to be ready in order to append links.
362
362
if ( ! document . documentElement ) return ;
363
363
364
- this . hintMarkerContainingDiv = null ;
364
+ this . containerEl = null ;
365
365
// Function that does the appropriate action on the selected link.
366
366
this . linkActivator = undefined ;
367
367
// The link-hints "mode" (in the key-handler, indicator sense).
@@ -407,20 +407,28 @@ class LinkHintsMode {
407
407
}
408
408
409
409
renderHints ( ) {
410
+ if ( this . containerEl == null ) {
411
+ const div = DomUtils . createElement ( "div" ) ;
412
+ div . id = "vimiumHintMarkerContainer" ;
413
+ div . className = "vimiumReset" ;
414
+ this . containerEl = div ;
415
+ document . documentElement . appendChild ( div ) ;
416
+ }
417
+
410
418
// Append these markers as top level children instead of as child nodes to the link itself,
411
419
// because some clickable elements cannot contain children, e.g. submit buttons.
412
- this . hintMarkerContainingDiv = DomUtils . addElementsToPage (
413
- this . hintMarkers . filter ( ( m ) => m . isLocalMarker ( ) ) . map ( ( m ) => m . element ) ,
414
- { id : "vimiumHintMarkerContainer" , className : "vimiumReset" }
415
- ) ;
420
+ const markerEls = this . hintMarkers . filter ( ( m ) => m . isLocalMarker ( ) ) . map ( ( m ) => m . element ) ;
421
+ for ( const el of markerEls ) {
422
+ this . containerEl . appendChild ( el ) ;
423
+ }
416
424
417
425
// TODO(philc): 2024-03-27 Remove this hasPopoverSupport check once Firefox has popover support.
418
426
// Also move this CSS into vimium.css.
419
- const hasPopoverSupport = this . hintMarkerContainingDiv . showPopover != null ;
427
+ const hasPopoverSupport = this . containerEl . showPopover != null ;
420
428
if ( hasPopoverSupport ) {
421
- this . hintMarkerContainingDiv . popover = "manual" ;
422
- this . hintMarkerContainingDiv . showPopover ( ) ;
423
- Object . assign ( this . hintMarkerContainingDiv . style , {
429
+ this . containerEl . popover = "manual" ;
430
+ this . containerEl . showPopover ( ) ;
431
+ Object . assign ( this . containerEl . style , {
424
432
top : 0 ,
425
433
left : 0 ,
426
434
position : "absolute" ,
@@ -762,10 +770,10 @@ class LinkHintsMode {
762
770
}
763
771
764
772
removeHintMarkers ( ) {
765
- if ( this . hintMarkerContainingDiv ) {
766
- DomUtils . removeElement ( this . hintMarkerContainingDiv ) ;
773
+ if ( this . containerEl ) {
774
+ DomUtils . removeElement ( this . containerEl ) ;
767
775
}
768
- this . hintMarkerContainingDiv = null ;
776
+ this . containerEl = null ;
769
777
}
770
778
}
771
779
0 commit comments