1+ // Function to add the "Mapa" button to the navigation menu
2+ function addMapButton ( ) {
3+ // Avoid duplicate buttons
4+ if ( document . querySelector ( "#map-button" ) ) return ;
5+
6+ // Locate the navigation menu by its role or other identifying features
7+ const menuContainer = document . querySelector ( 'div[role="list"]' ) || document . querySelector ( '.qogDvd' ) ;
8+
9+ if ( ! menuContainer ) {
10+ console . warn ( "Menu container not found. Retrying..." ) ;
11+ return ; // Exit if the menu is not found
12+ }
13+
14+ console . log ( "Menu container found:" , menuContainer ) ;
15+
16+ // Create the button
17+ const button = document . createElement ( "a" ) ;
18+ button . id = "map-button" ;
19+ button . innerText = "Mapa" ;
20+ button . href = `https://www.google.com/maps?q=${ encodeURIComponent ( document . title ) } ` ;
21+ button . target = "_blank" ; // Open in a new tab
22+ button . setAttribute ( "role" , "link" ) ;
23+ button . setAttribute ( "aria-label" , "Mapa" ) ;
24+
25+ // Add styles inline to prevent dependency on external classes
26+ button . style . display = "inline-block" ;
27+ button . style . padding = "6px 12px" ;
28+ button . style . margin = "5px" ;
29+ button . style . textDecoration = "none" ;
30+ button . style . color = "#1a73e8" ; // Matches Google's link color
31+ button . style . fontSize = "14px" ;
32+ button . style . lineHeight = "22px" ;
33+ button . style . borderRadius = "4px" ;
34+ button . style . cursor = "pointer" ;
35+
36+ // Add hover effect
37+ button . addEventListener ( "mouseover" , ( ) => {
38+ button . style . backgroundColor = "#f1f3f4" ;
39+ } ) ;
40+ button . addEventListener ( "mouseout" , ( ) => {
41+ button . style . backgroundColor = "transparent" ;
42+ } ) ;
43+
44+ // Wrap the button in a div (to mimic other menu items)
45+ const buttonWrapper = document . createElement ( "div" ) ;
46+ buttonWrapper . role = "listitem" ;
47+ buttonWrapper . style . display = "inline-block" ; // Matches layout
48+ buttonWrapper . appendChild ( button ) ;
49+
50+ // Insert the button at the beginning of the navigation menu
51+ menuContainer . insertBefore ( buttonWrapper , menuContainer . firstChild ) ;
52+
53+ console . log ( "Mapa button added successfully." ) ;
54+ }
55+
56+ // Initialize a MutationObserver to handle dynamic changes
57+ const observer = new MutationObserver ( ( ) => {
58+ addMapButton ( ) ; // Retry adding the button on DOM changes
59+ } ) ;
60+
61+ // Start observing the entire document for changes
62+ observer . observe ( document . body , { childList : true , subtree : true } ) ;
63+
64+ // Attempt initial injection
65+ addMapButton ( ) ;
66+
0 commit comments