nfc-web/web/nfc-theme/static/geo.js

48 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-05-21 15:54:20 +03:00
// reformat geo: links based on platform
2023-04-30 14:08:32 +03:00
const ua = String(platform.os).toLowerCase();
const android = ua.indexOf("android") > -1;
const ios = ua.indexOf("ios") > -1;
const windows = ua.indexOf("windows") > -1;
const linux = ua.indexOf("linux") > -1;
const mac = ua.indexOf("macos") > -1;
2023-05-01 22:59:40 +03:00
var hashlinks = document.querySelectorAll('[href*="geo:"]');
2023-05-01 21:58:23 +03:00
var hasharray = [...hashlinks];
if ( hasharray.length > 0 ) {
hasharray.forEach(hashlink => {
2023-05-01 22:59:40 +03:00
const geolink = hashlink.getAttribute("href").match(/(-?\d+(\.\d+)?),\s*(-?\d+(\.\d+)?)/g);
var latlon;
if ( geolink.length > 1 && geolink[0] == '0,0') latlon = geolink[1];
else latlon = geolink[0];
if ( windows || mac || linux ) hashlink.href = "https://maps.google.com/?q=" + latlon;
else if ( android ) hashlink.href = "geo:0,0?q=" + latlon;
else if ( ios ) hashlink.href = "http://maps.apple.com/?ll=" + latlon + "&q=" + hashlink.innerHTML;
2023-05-01 21:58:23 +03:00
});
2023-05-21 15:54:20 +03:00
}
// fingerprint user
2023-05-21 16:11:07 +03:00
2023-05-22 01:00:30 +03:00
const generateUUID = () => {
let
d = new Date().getTime(),
d2 = ((typeof performance !== 'undefined') && performance.now && (performance.now() * 1000)) || 0;
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
let r = Math.random() * 16;
if (d > 0) {
r = (d + r) % 16 | 0;
d = Math.floor(d / 16);
} else {
r = (d2 + r) % 16 | 0;
d2 = Math.floor(d2 / 16);
}
return (c == 'x' ? r : (r & 0x7 | 0x8)).toString(16);
});
};
if ( !Cookies.get('nfcexplorer') ) {
2023-05-22 01:03:33 +03:00
Cookies.set('nfcexplorer', generateUUID())
2023-05-22 01:00:30 +03:00
}
2023-05-22 00:19:32 +03:00
fetch('https://nmns.place/track?' + new URLSearchParams({
2023-05-22 01:00:30 +03:00
hash: Cookies.get('nfcexplorer'),
2023-05-21 21:39:29 +03:00
ua: ua,
}));