29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
// Points the main button at this visitor's platform. The download cards in index.html are the only list of
|
|
// links: release a platform there and this picks it up. Without JavaScript the page still works.
|
|
const NAMES = { ios: "iPhone", mac: "Mac", android: "Android", windows: "Windows", linux: "Linux" };
|
|
|
|
function detect() {
|
|
const ua = navigator.userAgent;
|
|
if (/iPhone|iPad|iPod/.test(ua) || (/Macintosh/.test(ua) && navigator.maxTouchPoints > 1)) return "ios";
|
|
if (/Android/.test(ua)) return "android";
|
|
if (/Macintosh/.test(ua)) return "mac";
|
|
if (/Windows/.test(ua)) return "windows";
|
|
if (/Linux|X11/.test(ua)) return "linux";
|
|
return null;
|
|
}
|
|
|
|
const os = detect();
|
|
const card = os && document.querySelector(`.card[data-os="${os}"]`);
|
|
if (card) {
|
|
card.classList.add("yours");
|
|
const cta = document.getElementById("hero-cta");
|
|
const note = document.getElementById("hero-note");
|
|
const link = card.querySelector("a.btn");
|
|
if (card.classList.contains("soon")) {
|
|
note.textContent = `Kestrove for ${NAMES[os]} is coming soon.`;
|
|
} else if (link) {
|
|
cta.href = link.href;
|
|
cta.textContent = link.dataset.label;
|
|
}
|
|
}
|