-
-
Save LatinSuD/e89119adcf910047e4dde9374bbe43df to your computer and use it in GitHub Desktop.
Bring back the google maps button when searching on google
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Google Maps in Google Search | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-03-13 | |
// @description Bring google maps button back | |
// @author Daan-Grashoff / LatinSuD | |
// @match https://www.google.com/search* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
/* TODO: | |
- Hay varios diseños muy distintos, aunque visualmente se parecen. Sacar uno a uno o usar una heuristica. | |
- No me gusta identificar por "classname". | |
- Identificar por palabras de un idioma concreto como "Todo" "Imagenes", tampoco me mola. | |
- Hay veces que si saca los maps de manera nativa: Evitar que salga en esos casos | |
*/ | |
const tabsContainer = document.querySelector('.crJ18e, .T47uwc'); | |
const clickableMapThumbnail = document.querySelector('#lu_map'); | |
console.log("EA"); | |
if (tabsContainer) { | |
const mapsLink = document.createElement('a'); | |
mapsLink.textContent = 'Maps'; | |
let mapsButton; | |
if (tabsContainer.children[2].nodeName == 'DIV') { | |
// Divs are in main tab | |
mapsButton = document.createElement('div'); | |
mapsButton.appendChild(mapsLink); | |
} else { | |
// "A" are in other pages | |
mapsButton = mapsLink; | |
} | |
//mapsButton.classList.add('nPDzT', 'T3FoJb'); | |
/* | |
const mapDiv = document.createElement('div'); | |
mapDiv.jsname = 'bVqjv'; | |
//mapDiv.classList.add('GKS7s'); | |
*/ | |
/*const mapSpan = document.createElement('span'); | |
//mapSpan.classList.add('FMKtTb', 'UqcIvb'); | |
mapSpan.jsname = 'pIvPIe'; | |
mapSpan.textContent = 'Maps'; | |
*/ | |
//mapDiv.appendChild(mapSpan); | |
//mapsButton.appendChild(mapDiv); | |
const searchQuery = new URLSearchParams(window.location.search).get('q'); | |
const parts = new URL(window.location).hostname.split('.'); | |
const topLevelDomainCode = parts[parts.length - 1]; | |
const mapsLinkURL = `http://maps.google.${topLevelDomainCode}/maps?q=${searchQuery};` | |
mapsLink.href = mapsLinkURL; | |
if (clickableMapThumbnail) { | |
const padre=clickableMapThumbnail.parentNode; | |
// some times the map is already son of a link, others not | |
if (padre.nodeName == 'A') { | |
padre.href = mapsLink; | |
} else { | |
const mapsLink2 = document.createElement('a'); | |
mapsLink2.href=mapsLinkURL; | |
padre.appendChild(mapsLink2); | |
mapsLink2.appendChild(clickableMapThumbnail); | |
} | |
} | |
tabsContainer.insertBefore(mapsButton, tabsContainer.lastChild); | |
}})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment