Advertisement
Guest User

Untitled

a guest
Apr 8th, 2024
2,836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Google maps addon
  3. // @namespace    http://tampermonkey.net/
  4. // @version      2024-03-21
  5. // @description  Bring google maps button back
  6. // @author       You
  7. // @match        https://www.google.com/search*
  8. // @include      https://www.google.tld/search*
  9. // @icon         https://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png
  10. // @grant        none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.   'use strict';
  15.  
  16.   function addMapsButton() {
  17.     // Find the list container of existing tabs
  18.     const tabsContainer = document.querySelector('.crJ18e');
  19.  
  20.     // If tabs exist, proceed
  21.     if (tabsContainer) {
  22.       // Create the Maps button elements (updated)
  23.       const mapsListItem = document.createElement('div');
  24.       mapsListItem.jsname = 'VIftV';
  25.       // mapsListItem.classList.add('Ap1Qsc');
  26.       mapsListItem.setAttribute('role', 'listitem');
  27.  
  28.       // Replace this entire section with the provided <a> element
  29.       const mapsButton = document.createElement('a');
  30.       mapsButton.jsname = "ONH4Gc";
  31.       mapsButton.classList.add("LatpMc");
  32.       mapsButton.classList.add("nPDzT");
  33.       mapsButton.classList.add("T3FoJb");
  34.       mapsButton.dataset.navigation = "server";  // Update the attribute name
  35.       mapsButton.dataset.hveid = "CAEQCA";
  36.       // Get the search query from the URL
  37.       const searchQuery = new URLSearchParams(window.location.search).get('q');
  38.  
  39.       // Construct the Maps link with the query
  40.       const mapsLink = `//maps.google.com/maps?q=${searchQuery}`;
  41.       mapsButton.href = mapsLink;
  42.  
  43.       //mapsButton.textContent = "Maps"; // Set the inner text
  44.       const mapsButtonText = document.createElement('div');
  45.       mapsButtonText.jsname = "bVqjv";
  46.       mapsButtonText.classList.add("YmvwI");
  47.       mapsButtonText.textContent = "Maps";
  48.       mapsButton.appendChild(mapsButtonText);
  49.  
  50.       // Append the mapsButton to the list item
  51.       mapsListItem.appendChild(mapsButton);
  52.  
  53.       // Insert the Maps button at the beginning of the tabs container
  54. tabsContainer.insertBefore(mapsListItem, tabsContainer.childNodes[1]);
  55.     }
  56.   }
  57.  
  58.   // Call the function to add the button
  59.   addMapsButton();
  60. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement