Skip to content

Instantly share code, notes, and snippets.

@cave2006
Last active January 19, 2024 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cave2006/0e69ebeb63821012a1352cd22805c447 to your computer and use it in GitHub Desktop.
Save cave2006/0e69ebeb63821012a1352cd22805c447 to your computer and use it in GitHub Desktop.
Код для вставки универсального кода в кнопки на мобильном
// Находим и записываем координаты обекта
55.002707° 82.975013°
// addition js
<script>
if(navigator.vendor != null && navigator.vendor.match(/Apple Computer, Inc./) && navigator.userAgent.match(/iPhone/i) || (navigator.userAgent.match(/iPod/i)))
{
document.querySelector('.geo').style.display = 'none';
}
else if (navigator.vendor != null && navigator.vendor.match(/Apple Computer, Inc./) && navigator.userAgent.match(/iPad/i))
{
document.querySelector('.geo').style.display = 'none';
}
else if (navigator.vendor != null && navigator.vendor.match(/Apple Computer, Inc./) && navigator.userAgent.indexOf('Safari') != -1)
{
document.querySelector('.geo').style.display = 'none';
}
else if (navigator.vendor == null || navigator.vendor != null)
{
document.querySelector('.igeo').style.display = 'none';
}
</script>
//optimized js
document.addEventListener('DOMContentLoaded', function () {
const vendorMatch = navigator.vendor && navigator.vendor.match(/Apple Computer, Inc./);
const userAgentMatch = navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.indexOf('Safari') != -1;
if (vendorMatch && userAgentMatch) {
document.querySelector('.geo').style.display = 'none';
} else if (navigator.vendor == null || navigator.vendor != null) {
document.querySelector('.igeo').style.display = 'none';
}
});
//new version js
document.addEventListener('DOMContentLoaded', function () {
const vendorMatch = navigator.vendor && navigator.vendor.match(/Apple Computer, Inc./);
const safariMatch = navigator.userAgent.match(/Safari/i) && parseInt(navigator.userAgent.match(/Version\/[\d.]+/)![0]) >= 10 && parseFloat(navigator.userAgent.match(/OS X/i)[0].substr(0, parseFloat(navigator.userAgent.match(/OS X/i)[0].substr(0, parseFloat(navigator.userAgent.match(/OS X/i)[0].match(/OS X/i)[0].substr(0, 2))-1))) >= 10;
const iphoneMatch = navigator.userAgent.match(/iPhone/i) && parseInt(navigator.userAgent.match(/CPU like Mac OS X/i)[0].match(/CPU like Mac OS X/i)[1].substr(0, 2)) > 1 && parseInt(navigator.userAgent.match(/OS X/i)[0].substr(0, parseFloat(navigator.userAgent.match(/OS X/i)[0].match(/OS X/i)[0].substr(0, parseFloat(navigator.userAgent.match(/OS X/i)[0].substr(0, parseFloat(navigator.userAgent.match(/OS X/i)[0].substr(0, parseFloat(navigator.userAgent.match(/OS X/i)[0].substr(0, parseFloat(navigator.userAgent.match(/OS X/i)[0].substr(0, 2))-1)))-1))-1)) >= 8;
if (vendorMatch && (safariMatch || iphoneMatch)) {
document.querySelector('.geo').style.display = 'none';
} else if (navigator.vendor == null || navigator.vendor != null) {
document.querySelector('.igeo').style.display = 'none';
}
});
//add desktop as cgeo class
document.addEventListener('DOMContentLoaded', function () {
const vendorMatch = navigator.vendor && navigator.vendor.match(/Apple Computer, Inc./);
const safariMatch = navigator.userAgent.match(/Safari/i) && parseFloat(navigator.userAgent.match(/Version\/[\d.]+/)![0].substr(7)) >= 10 && parseFloat(navigator.userAgent.match(/OS X/i)[0].substr(4)) >= 10;
const iphoneMatch = navigator.userAgent.match(/iPhone/i) && parseInt(navigator.userAgent.match(/CPU like Mac OS X/i)[0].substr(11)) > 1 && parseFloat(navigator.userAgent.match(/CPU like Mac OS X/i)[0].substr(22)) >= 8;
const desktopMatch = window.matchMedia('(min-width: 960px)').matches;
if (vendorMatch && (safariMatch || iphoneMatch)) {
if (desktopMatch) {
document.querySelector('.geo').style.display = 'none';
document.querySelector('.cgeo').style.display = 'block';
}
} else if (navigator.vendor == null || navigator.vendor != null) {
if (desktopMatch) {
document.querySelector('.igeo').style.display = 'none';
document.querySelector('.cgeo').style.display = 'block';
}
}
});
// addition html code
<a href="geo:55.0560,82.9643" class="uk-icon-link uk-text-primary geo" uk-icon="location" onClick="ym(xxxxxxxx, 'reachGoal', 'LOCATION');"></a>
<a href="https://maps.apple.com/maps?q=55.0560,82.9643" class="uk-icon-link uk-text-primary igeo" uk-icon="location" onClick="ym(xxxxxxxx, 'reachGoal', 'LOCATION');"></a>
@cave2006
Copy link
Author

add optimized js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment