Google Maps Tab für EU Benutzer

Fügt den Maps-Tab zur Google-Suche hinzu, wenn er in der EU nicht angezeigt wird

  1. // ==UserScript==
  2. // @name Google Maps Tab für EU Benutzer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Fügt den Maps-Tab zur Google-Suche hinzu, wenn er in der EU nicht angezeigt wird
  6. // @author Mindworker
  7. // @match https://www.google.com/search*
  8. // @match https://www.google.de/search*
  9. // @match https://www.google.at/search*
  10. // @match https://www.google.fr/search*
  11. // @match https://www.google.it/search*
  12. // @match https://www.google.es/search*
  13. // @match https://www.google.nl/search*
  14. // @match https://www.google.be/search*
  15. // @match https://www.google.pl/search*
  16. // @grant none
  17. // @license MIT
  18. // ==/UserScript==
  19.  
  20. (function() {
  21. 'use strict';
  22.  
  23. // Funktion zum Überprüfen, ob der Maps-Tab existiert
  24. function mapsTabExists() {
  25. const tabElements = document.querySelectorAll('div[role="navigation"] a');
  26. for (let tab of tabElements) {
  27. if (tab.textContent.includes('Maps') || tab.textContent.includes('Karten')) {
  28. return true;
  29. }
  30. }
  31. return false;
  32. }
  33.  
  34. // Funktion zum Erstellen und Einfügen des Maps-Tabs
  35. function addMapsTab() {
  36. // Warte, bis die Tab-Navigation geladen ist
  37. const checkForNavigation = setInterval(function() {
  38. const tabNavigation = document.querySelector('div[role="navigation"]');
  39. if (tabNavigation && !mapsTabExists()) {
  40. clearInterval(checkForNavigation);
  41. // Erstelle den neuen Tab
  42. const tabsContainer = tabNavigation.querySelector('div');
  43. if (tabsContainer) {
  44. // Bestehende Tabs finden
  45. const existingTabs = tabsContainer.querySelectorAll('a');
  46. if (existingTabs.length > 0) {
  47. // Klone einen bestehenden Tab als Vorlage
  48. const templateTab = existingTabs[0].cloneNode(true);
  49. // Aktuellen Suchbegriff ermitteln
  50. const searchQuery = new URLSearchParams(window.location.search).get('q') || '';
  51. // Tab anpassen
  52. templateTab.href = `https://www.google.com/maps/search/${encodeURIComponent(searchQuery)}`;
  53. // Sprachabhängige Bezeichnung
  54. const language = document.documentElement.lang || navigator.language || 'en';
  55. const tabText = language.startsWith('de') ? 'Karten' : 'Maps';
  56. // Text und Aussehen anpassen
  57. if (templateTab.querySelector('span')) {
  58. templateTab.querySelector('span').textContent = tabText;
  59. } else {
  60. templateTab.textContent = tabText;
  61. }
  62. // Tab an geeigneter Stelle einfügen (nach "Bilder" bzw. "Images")
  63. let insertAfter = existingTabs[0];
  64. for (let tab of existingTabs) {
  65. const tabText = tab.textContent.toLowerCase();
  66. if (tabText.includes('bilder') || tabText.includes('images')) {
  67. insertAfter = tab;
  68. break;
  69. }
  70. }
  71. // Tab einfügen
  72. insertAfter.parentNode.insertBefore(templateTab, insertAfter.nextSibling);
  73. console.log('Maps-Tab wurde hinzugefügt');
  74. }
  75. }
  76. }
  77. }, 500);
  78. }
  79.  
  80. // Initialisierung
  81. window.addEventListener('load', function() {
  82. setTimeout(addMapsTab, 1000);
  83. });
  84. // Auch bei AJAX-Navigation (wenn Google Ergebnisse dynamisch nachlädt)
  85. const observer = new MutationObserver(function(mutations) {
  86. for (let mutation of mutations) {
  87. if (mutation.type === 'childList' && !mapsTabExists()) {
  88. addMapsTab();
  89. break;
  90. }
  91. }
  92. });
  93. // Beobachtung des DOM starten
  94. setTimeout(function() {
  95. const searchResults = document.getElementById('search');
  96. if (searchResults) {
  97. observer.observe(searchResults, { childList: true, subtree: true });
  98. }
  99. }, 1500);
  100. })();