@mt-kit/utils
Version:
70 lines (56 loc) • 2.58 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>获取设备信息</title>
<script src="../lib/index.js"></script>
</head>
<body>
<div>
<p>语言: <span id="language"></span></p>
<p>浏览器: <pre id="browser"></pre></p>
<p>操作系统: <span id="operatingSystem"></span></p>
<p>在线状态: <span id="onLine"></span></p>
<p>屏幕: <pre id="screen"></pre></p>
<p>位置: <pre id="location"></pre></p>
<p>公网IP: <span id="publicIp"></span></p>
<p>CPU核心数: <span id="cpuCores"></span></p>
<p>内存信息: <pre id="memory"></pre></p>
<p>硬件并发数: <span id="hardwareConcurrency"></span></p>
<p>设备特性: <pre id="features"></pre></p>
<p>传感器: <pre id="sensor"></pre></p>
<p>国际化: <pre id="i18n"></pre></p>
<p>所有信息: <pre id="all"></pre></p>
</div>
</body>
</html>
<script>
document.getElementById('browser').innerText = JSON.stringify(microUtil.deviceBrowser(), null, 2);
document.getElementById('operatingSystem').innerText = microUtil.deviceOperatingSystem();
document.getElementById('language').innerText = microUtil.deviceLanguage();
document.getElementById('onLine').innerText = microUtil.deviceOnLine() ? "在线" : "离线";
document.getElementById('screen').innerText = JSON.stringify(microUtil.deviceScreen(), null, 2);
microUtil.deviceLocation().then(res => {
document.getElementById('location').innerText = JSON.stringify(res, null, 2);
})
microUtil.devicePublicIp().then(res => {
document.getElementById('publicIp').innerText = res;
})
document.getElementById('cpuCores').innerText = microUtil.deviceCpuCores();
document.getElementById('memory').innerText = JSON.stringify(microUtil.deviceMemory(), null, 2);
document.getElementById('hardwareConcurrency').innerText = microUtil.deviceHardwareConcurrency();
document.getElementById('features').innerText = JSON.stringify(microUtil.deviceFeatures(), null, 2);
document.getElementById('sensor').innerText = JSON.stringify(microUtil.deviceSensor(), null, 2);
document.getElementById('i18n').innerText = JSON.stringify(microUtil.deviceI18n(), null, 2);
// 获取所有设备信息(异步)
microUtil.deviceAll(
{
location: false,
}
).then(allInfo => {
document.getElementById('all').innerText = JSON.stringify(allInfo, null, 2);
}).catch(error => {
document.getElementById('all').innerText = `获取失败: ${error.message}`;
});
</script>