-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
88 lines (78 loc) · 3.1 KB
/
index.html
File metadata and controls
88 lines (78 loc) · 3.1 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html lang="lt">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>AtomChain</title>
<script>
(function () {
// Konfigūruok čia:
const desktopURL = 'atomchain-desk.html'; // arba pilnas URL
const mobileURL = 'atomchain-mob.html'; // arba pilnas URL
// 1) Modernus API (Chrome 85+, Edge, kt.) — greitas ir patikimas, jei prieinamas
function isMobile_byUserAgentData() {
try {
// navigator.userAgentData may exist and has .mobile boolean
if (
navigator.userAgentData &&
typeof navigator.userAgentData.mobile === 'boolean'
) {
return navigator.userAgentData.mobile;
}
} catch (e) {}
return null;
}
// 2) Tradicinis userAgent regex fallback
function isMobile_byUserAgentString() {
const ua = navigator.userAgent || '';
// Paprasti mobile identifikatoriai
const mobileRegex =
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
return mobileRegex.test(ua);
}
// 3) Ekrano pločio patikra kaip papildomas heuristinis požymis
function isMobile_byScreenWidth() {
try {
return Math.min(window.screen.width, window.screen.height) <= 768;
} catch (e) {
return false;
}
}
// Sumuojame: bandome userAgentData, jeigu grąžino null - naudojame UA string + width
function detectMobile() {
const byUAData = isMobile_byUserAgentData();
if (byUAData !== null) return byUAData;
// jei nėra modernaus API — deriname kelių heuristikų rezultatus
const uaGuess = isMobile_byUserAgentString();
const wGuess = isMobile_byScreenWidth();
// Jeigu bent viena sako mobile, traktuojam kaip mobile
return uaGuess || wGuess;
}
// Vykdom redirect (vietoje replace galite naudoti href)
const isMobile = detectMobile();
// Jei norite testuoti be redirect — galite console.log vietoje redirect
// console.log("Is mobile?", isMobile);
if (isMobile) {
// replace() pakeis istoriją (naudinga negrįžtantiems)
window.location.replace(mobileURL);
} else {
window.location.replace(desktopURL);
}
// --- Pasirinktinai: jei nenorite automatinio redirect (pvz. SEO), galite parodyti nuorodas:
// document.addEventListener("DOMContentLoaded", () => { ... })
})();
</script>
</head>
<body>
<p>
Nukreipinimas vyksta... Jei tuoj nieko neįvyko, spauskite:
<a id="desktopLink" href="desktop.html">Desktop</a> |
<a id="mobileLink" href="mobile.html">Mobile</a>
</p>
<script>
// Užtikrinti, kad nuorodos atitiktų konfigūrą aukščiau (naudinga testavimui)
document.getElementById('desktopLink').href = 'desktop.html';
document.getElementById('mobileLink').href = 'mobile.html';
</script>
</body>
</html>