11 lines
563 B
JavaScript
11 lines
563 B
JavaScript
// Gröbste Bot- und Gerätetyp-Erkennung; der User-Agent wird danach verworfen.
|
|
const BOT = /bot|crawl|spider|slurp|headless|lighthouse|pingdom|uptime|curl|wget|python|go-http|java\/|facebookexternalhit|preview/i;
|
|
|
|
export function classifyUa(ua) {
|
|
const s = typeof ua === 'string' ? ua : '';
|
|
if (!s || BOT.test(s)) return { bot: true, device: 'd' };
|
|
if (/Mobi|Android.*Mobile|iPhone/i.test(s)) return { bot: false, device: 'm' };
|
|
if (/iPad|Tablet|Android(?!.*Mobile)/i.test(s)) return { bot: false, device: 't' };
|
|
return { bot: false, device: 'd' };
|
|
}
|