Advertisement
Guest User

Untitled

a guest
Apr 11th, 2024
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Google maps addon
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-02-13
  5. // @description Bring google maps button back
  6. // @author You
  7. // @match https://www.google.com/*
  8. // @match https://www.google.nl/*
  9. // @match https://www.google.pl/*
  10. // @icon https://www.google.com/
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function () {
  15.  
  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.  
  25. // Get the search query from the URL
  26. const searchQuery = new URLSearchParams(window.location.search).get('q');
  27.  
  28. // Construct the Maps link with the query
  29. const mapsLink = `${window.location.origin}/maps?q=${searchQuery}`;
  30.  
  31. // If map image exists
  32. if (mapImage) {
  33. const anchorElement = document.createElement('a');
  34. anchorElement.href = mapsLink;
  35. mapImage.parentNode.insertBefore(anchorElement, mapImage);
  36. anchorElement.appendChild(mapImage);
  37. }
  38.  
  39. // If links exist, proceed
  40. if (linksContainer) {
  41. // Create the Maps button
  42. const mapsButtonL = document.createElement('a');
  43. mapsButtonL.classList.add('nPDzT', 'T3FoJb'); // Style to match other tabs
  44.  
  45. // Create the inner elements for the Maps button
  46. const mapDivL = document.createElement('div');
  47. mapDivL.jsname = 'bVqjv';
  48. mapDivL.classList.add('YmvwI'); //GKS7s
  49.  
  50. const mapSpanL = document.createElement('span');
  51. mapSpanL.classList.add('FMKtTb', 'UqcIvb');
  52. mapSpanL.jsname = 'pIvPIe';
  53. mapSpanL.textContent = 'Maps';
  54.  
  55. // Assemble the elements
  56. mapDivL.appendChild(mapSpanL);
  57. mapsButtonL.appendChild(mapDivL);
  58. mapsButtonL.href = mapsLink;
  59.  
  60. // Insert the Maps button at the beginning of the tabs container
  61. linksContainer.prepend(mapsButtonL);
  62. }
  63.  
  64. // If tabs exist, proceed
  65. if (tabsContainer) {
  66. // Create the Maps button
  67. const mapsButtonT = document.createElement('a');
  68. mapsButtonT.classList.add('nPDzT', 'T3FoJb'); // Style to match other tabs
  69.  
  70. // Create the inner elements for the Maps button
  71. const mapDivT = document.createElement('div');
  72. mapDivT.jsname = 'bVqjv';
  73. mapDivT.classList.add('GKS7s');
  74.  
  75. const mapSpanT = document.createElement('span');
  76. mapSpanT.classList.add('FMKtTb', 'UqcIvb');
  77. mapSpanT.jsname = 'pIvPIe';
  78. mapSpanT.textContent = 'Maps';
  79.  
  80. // Assemble the elements
  81. mapDivT.appendChild(mapSpanT);
  82. mapsButtonT.appendChild(mapDivT);
  83. mapsButtonT.href = mapsLink;
  84.  
  85. // Insert the Maps button at the beginning of the tabs container
  86. tabsContainer.prepend(mapsButtonT);
  87. }
  88.  
  89. }
  90.  
  91. // Call the function to add the button
  92. addMapsLink();
  93.  
  94. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement