detection
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -12,2 +12,8 @@ /** | ||
} | ||
export declare class DateTime { | ||
readonly timezone: string | undefined; | ||
readonly datetime: string; | ||
readonly timestamp: number; | ||
constructor(datetime: string, timestamp: number, timezone: string); | ||
} | ||
export declare class BaseInfo extends Info { | ||
@@ -17,2 +23,4 @@ readonly os: string; | ||
readonly ua: string; | ||
ip: string | undefined; | ||
localtime: DateTime | undefined; | ||
/** | ||
@@ -19,0 +27,0 @@ * 原始屏幕分辨率信息 |
@@ -10,3 +10,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
// @ts-ignore | ||
import * as UA from 'express-useragent'; | ||
let win = window; | ||
if (!navigator.mediaDevices) { | ||
@@ -23,2 +25,9 @@ throw new Error('Browser is too old'); | ||
} | ||
export class DateTime { | ||
constructor(datetime, timestamp, timezone) { | ||
this.datetime = datetime; | ||
this.timestamp = timestamp; | ||
this.timezone = timezone; | ||
} | ||
} | ||
export class BaseInfo extends Info { | ||
@@ -125,2 +134,22 @@ constructor(os, browser, ua, screen, language, processor) { | ||
info.network = rs.reduce((total, num) => total + num) / size; | ||
// 获取地区 与 时间 | ||
let now = new Date(); | ||
info.localtime = { | ||
datetime: `${now.getFullYear()}年${now.getMonth() + 1}月${now.getDate()}日 ${now.getHours()}时${now.getMinutes()}分${now.getSeconds()}秒`, | ||
timestamp: now.getTime(), | ||
timezone: 'UTC+' + (0 - now.getTimezoneOffset() / 60) | ||
}; | ||
const getIp = () => { | ||
return new Promise(resolve => { | ||
win.ipCallback = function (info) { | ||
resolve(info.ip); | ||
}; | ||
let script = document.createElement('script'); | ||
script.async = true; | ||
script.src = 'https://www.taobao.com/help/getip.php'; | ||
script.onerror = () => resolve(void 0); | ||
document.head.append(script); | ||
}); | ||
}; | ||
info.ip = yield getIp(); | ||
return info; | ||
@@ -127,0 +156,0 @@ }); |
{ | ||
"name": "detection", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index", |
14079
393