Detector 前端浏览器 UA 客户端信息识别模块

2023-01-04 0 544

应用程序重要信息辨识组件,用作自动辨识使用者采用的应用程序自然环境。主要包括:

硬体电子设备。作业系统。应用程序。应用程序图形发动机。

辨识回到的 detector 第一类重要信息结构如下表所示:

detector ={ device:{ name:”iphone”, version:-1, fullVersion:”-1″,[iphone]:-1}, os:{ name:”ios”, version:6.1, fullVersion:”6.1″,[ios]:6.1}, browser:{ name:”chrome”: version:26.0, fullVersion:”26.0.1410.50″, mode:26.0, fullMode:”26.0.1410.50″, compatible: false,[chrome]:26.0}, engine:{ name:”webkit”, version:536.26, fullVersion:”536.26″, mode:523.26, fullMode:”523.26″, compatible: false,[webkit]:536.26}}

附注:下面的[iphone],[ios],[chrome],[webkit]是静态的,依照前述辨识到的重要信息相同而略有相同。

注:

那个版遵从 CommonJS 规范化,与此同时相容如前所述 Node 自然环境和 Web 应用程序自然环境运转。很多情景只须要单纯辨识某一的重要信息,能参照辨识某一应用程序最差课堂教学而无须采用 detector。

加装

via npm:

自上而下加装(-g)时,能在终端产品采用 detector 指示。

npm install detector [-g]

采用表明

Web 端采用

在应用程序情景下,通常常用采用实例如下表所示:

//导入 detector 第一类const detector = require(detector);//判断应用程序名detector.browser.name ===”chrome”// true//判断应用程序名方法2.!!detector.browser.ie // false//判断老旧应用程序if(detector.browser.ie && detector.browser.version <8){ alert(“你的应用程序太老了。”);}//判断 Trident 4(IE8)以下版应用程序发动机if(detector.engine.trident && detector.engine.mode <4){// hack code.}//收集应用程序详细重要信息detector.browser.name +”/”+ detector.browser.fullVersion;

Node.js 端采用

const detector = require(detector);//变量 d 是一个“detector 第一类”const d = detector.parse(userAgent);d.browser.name ===”chrome”;

API

{String} detector.device.name

电子设备名称。

{Number} detector.device.version

电子设备版号。

{String} detector.device.fullVersion

电子设备完整版号。

{Number} detector.device[devicename]

直接判断电子设备名。

能辨识的电子设备名称为:

pc: Windows PC.mac: Macintosh PC.iphone: iPhone.ipad: iPad.ipod: iPod.android: Android.blackberry:黑莓(Blackberry)手机。wp: Windows Phone.mi:小米。meizu:魅族。nexus: Nexus.nokia: Nokia.samsung:三星手机。aliyun:阿里云手机。huawei:华为手机。lenovo:联想手机。zte:中兴手机。vivo:步步高手机。htc: HTC。oppo: OPPO 手机。konka:康佳手机。sonyericsson:索尼爱立信手机。coolpad:酷派手机。lg: LG 手机。

NODE ONLY

noain:诺亚信huawei-honor:华为荣耀lephone:乐 Phoneasus:华硕alcatel一加蓝米E 派hikeqmi友信达:友信达优米嘉源intki星语欧奇海派广信:广信nibiru: nibiru神州青橙海信金立etonbohp小杨树语信nubia爱讯达寰宇通mofutinfocus大唐邦华天迈大显博瑞lingwiniusai波导德赛蓝魔美图opssonbenweehosinsmartisan:锤子, Smartisan.ephone佰事讯newmankonkahaiermototcl天语doov天时达

{String} detector.os.name

作业系统名。

{Number} detector.os.version

作业系统版号。

{String} detector.os.fullVersion

作业系统完整版号。

{Number} detector.os[osname]

直接判断作业系统。

能辨识的作业系统主要包括:

windows: Windows.macosx: Macintosh.ios: iOS.android: Android.chromeos: Chrome OS.linux: Linux.wp: Windows Phone.windowsce: Windows CE,主要包括 Windows Mobile, Smartphone, PPC.symbian: Symbian OS.blackberry: Blackberry 操作系统。yunos:阿里云系统。

NODE ONLY

meego: Meego.smartisan:锤子,Smartisan.

{String} detector.browser.name

应用程序名。

{Number} detector.browser.version

应用程序真实版。相容模式下应用程序声明自己是某老旧应用程序,但那个属性回到的是其真正的版号。

适用作收集统计分析应用程序重要信息。

例如:

IE9相容模式声明自己是 IE7,但是 detector.browser.version 回到9.0

{String} detector.browser.fullVersion

应用程序完整的真实版号。

{Number} detector.browser.mode

应用程序模式。即应用程序当时采用的模式,IE 相容模式时,version 和 mode 值相同。

{String} detector.browser.fullMode

浏览器模式的完整版号。

{Number} detector.browser[browsername]

直接判断应用程序。

能辨识的应用程序为:

ie: Microsoft Internet Explorer.chrome: Google Chrome.firefox: Mozilla Firefox.safari: Apple Safari.opera: Opera.360:主要包括奇虎360安全应用程序和360极速应用程序。maxthon:傲游应用程序(Maxthon)。sogou:搜狗应用程序(Sogou)。theworld:世界之窗应用程序(TheWorld)。green: GreenBrowser.qq: QQ 应用程序。tt: TencentTraveler.liebao:猎豹应用程序。tao:淘宝应用程序。coolnovo:枫树应用程序。saayaa:闪游应用程序。uc: UC 应用程序。mi:小米应用程序。baidu:百度应用程序。nokia:诺基亚应用程序。blackberry:黑莓默认应用程序,版号与系统版相同。webview: iOS 系统的提供的 WebView。yandex: Yandex YaBrowser.micromessenger 微信ali-ap:支付宝手机应用程序。ali-ap-pd:支付宝平板应用程序。ali-am:支付宝商户应用程序。ali-tb:淘宝手机应用程序。ali-tb-pd:淘宝平板应用程序。ali-tm:天猫手机应用程序。ali-tm-pd:天猫平板应用程序。

NODE ONLY

googlebot: Googlebot 网络爬虫。baiduspider: Baiduspider ,百度无线、网页搜索baiduspider-image:百度图片搜索baiduspider-video:百度视频搜索baiduspider-news:百度新闻搜索baiduspider-favo:百度收藏搜索baiduspider-cpro:百度联盟baiduspider-ads:百度商务搜索baiduboxapp:百度手机搜索应用程序bingbot: Bingbot 网络爬虫。msnbot: MSNBotnuhkbot: Nuhkbotalexabot: Alexabot.curl: curl.slurpbot: Yahoo! Slurp

{Boolean} detector.browser.compatible

应用程序是否处于相容模式。

{String} detector.engine.name

图形发动机名(又称排版发动机、应用程序内核)。

{Number} detector.engine.version

图形发动机版号。

{String} detector.engine.fullVersion

图形发动机完整版号。

{Number} detector.engine.mode

图形发动机模式,即 IE 应用程序的文档模式。

{String} detector.engine.fullMode

图形发动机模式完整版号。

{Number} detector.engine[enginename]

直接判断图形发动机。

能辨识的图形发动机为:

trident: Microsoft Trident.blink: Google Blink.webkit: Apple Webkit.gecko: Mozilla Gecko.presto: Opera Presto.androidwebkit: Android Webkit.coolpadwebkit: Coolpad Webkit.u2: UC 应用程序图形发动机 v2u3: UC 应用程序图形发动机 v3

{detector} detector.parse(String ua)

依照 userAgent 字符串辨识应用程序重要信息的接口。

服务端程序能采用那个接口辨识应用程序重要信息,由于服务端程序的特殊性,能补充更完善的检测规则。

对于不能辨识的重要信息,统一如下表所示:

所有不能辨识的名称均归类为 na,即 Not Available.所有不能辨识的版号归类为-1。

相关链接

Github 地址:https://github.com/hotoo/detector

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务