Google Search Maps Buttons

Adds maps buttons to Google Search and filters out -site:pinterest.* (modified from Daan Grashoff / Delivator)

  1. // ==UserScript==
  2. // @name Google Search Maps Buttons
  3. // @description Adds maps buttons to Google Search and filters out -site:pinterest.* (modified from Daan Grashoff / Delivator)
  4. // @version 0.1.1
  5. // @author mseitz
  6. // @namespace https://greasyfork.org/en/scripts/490916-google-search-maps-buttons
  7. // @include https://www.google.tld/search*
  8. // @icon https://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png
  9. // @grant none
  10. // @license CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
  11. // @homepageURL https://greasyfork.org/en/scripts/490916-google-search-maps-buttons
  12. // ==/UserScript==
  13.  
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. function addMapsLink() {
  19. // Find the existing results tabs (Images, News, etc.)
  20. const linksContainer = document.querySelector('.crJ18e');
  21. const tabsContainer = document.querySelector('.IUOThf');
  22. const mapImage = document.querySelector('#lu_map');
  23.  
  24. // Get the search query from the URL
  25. const searchQuery = new URLSearchParams(window.location.search).get('q').replace("-site:pinterest.*", '');
  26.  
  27. // Construct the Maps link with the query
  28. const mapsLink = `${window.location.origin}/maps?q=${searchQuery}`;
  29.  
  30. // If map image exists
  31. if (mapImage) {
  32. const anchorElement = document.createElement('a');
  33. anchorElement.href = mapsLink;
  34. mapImage.parentNode.insertBefore(anchorElement, mapImage);
  35. anchorElement.appendChild(mapImage);
  36. }
  37.  
  38. // If links exist, proceed
  39. if (linksContainer) {
  40. // Create the Maps button
  41. const mapsButtonL = document.createElement('a');
  42. mapsButtonL.classList.add('nPDzT', 'T3FoJb'); // Style to match other tabs
  43.  
  44. // Create the inner elements for the Maps button
  45. const mapDivL = document.createElement('div');
  46. mapDivL.jsname = 'bVqjv';
  47. mapDivL.classList.add('YmvwI'); //GKS7s
  48.  
  49. const mapSpanL = document.createElement('span');
  50. mapSpanL.classList.add('FMKtTb', 'UqcIvb');
  51. mapSpanL.jsname = 'pIvPIe';
  52. mapSpanL.textContent = 'Maps';
  53.  
  54. // Assemble the elements
  55. mapDivL.appendChild(mapSpanL);
  56. mapsButtonL.appendChild(mapDivL);
  57. mapsButtonL.href = mapsLink;
  58.  
  59. // Insert the Maps button at the beginning of the tabs container
  60. linksContainer.prepend(mapsButtonL);
  61. }
  62.  
  63. // If tabs exist, proceed
  64. if (tabsContainer) {
  65. // Create the Maps button
  66. const mapsButtonT = document.createElement('a');
  67. mapsButtonT.classList.add('nPDzT', 'T3FoJb'); // Style to match other tabs
  68.  
  69. // Create the inner elements for the Maps button
  70. const mapDivT = document.createElement('div');
  71. mapDivT.jsname = 'bVqjv';
  72. mapDivT.classList.add('GKS7s');
  73.  
  74. const mapSpanT = document.createElement('span');
  75. mapSpanT.classList.add('FMKtTb', 'UqcIvb');
  76. mapSpanT.jsname = 'pIvPIe';
  77. mapSpanT.textContent = 'Maps';
  78.  
  79. // Assemble the elements
  80. mapDivT.appendChild(mapSpanT);
  81. mapsButtonT.appendChild(mapDivT);
  82. mapsButtonT.href = mapsLink;
  83.  
  84. // Insert the Maps button at the beginning of the tabs container
  85. tabsContainer.prepend(mapsButtonT);
  86. }
  87.  
  88. }
  89.  
  90. // Call the function to add the button
  91. addMapsLink();
  92.  
  93. })();