-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_link_to_image.js
38 lines (34 loc) · 1.26 KB
/
add_link_to_image.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const url = window.location.href
if (url.startsWith('https://www.google.com/search')) {
const allImages = Array.from(document.querySelectorAll('img'))
allImages
.filter((img) => img.src.includes('/maps/'))
.forEach((img) => {
img.style.cursor = 'pointer'
const address = img
.closest('.lu_map_section')
?.closest('.dirs')
?.parentElement?.querySelector('b')
?.textContent?.trim()
img.addEventListener('click', (e) => {
window.open(
`https://www.google.fr/maps/place/${address?.replace(/\s/gm, '+') ?? ''
}`,
'_blank'
)
})
})
const isACompanyAddress = Array.from(document.querySelectorAll('a')).find(a => a.href?.includes('/maps/'))
if (isACompanyAddress) {
const companyMap = document.querySelector('#lu_map')
if (companyMap) {
companyMap.style.cursor = 'pointer'
companyMap.addEventListener('click', (e) => {
window.open(
isACompanyAddress.href,
'_blank'
)
})
}
}
}