How to use uaData method in wpt

Best JavaScript code snippet using wpt

tracker_ua_device.js

Source:tracker_ua_device.js Github

copy

Full Screen

1/*2 * Copyright © 2017 eqxiu.com. All rights reserved 北京中网易企秀科技有限公司3 *4 * author: Sun Xiaopeng 孙小朋5 * date: 2017/8/16 * description:7 */8var tracker_ua_device = function(ua) {9 var UA = tracker_ua_base;10 var uaData = new UA(ua);11 var match;12 var tmpMatch;13 // handle mobile device14 if (uaData.device.type === 'mobile' || uaData.device.type === 'tablet') {15 // get manufacturer through the key words16 if (match = ua.match(/(ZTE|Samsung|Motorola|HTC|Coolpad|Huawei|Lenovo|LG|Sony Ericsson|Oppo|TCL|Vivo|Sony|Meizu|Nokia)/i)) {17 uaData.device.manufacturer = match[1];18 if (uaData.device.model && uaData.device.model.indexOf(match[1]) >= 0) {19 uaData.device.model = uaData.device.model.replace(match[1], '');20 }21 }22 // handle Apple23 // 苹果就这3种iPod iPad iPhone24 if ( match = ua.match(/(iPod|iPad|iPhone)/i) ) {25 uaData.device.manufacturer = 'Apple';26 uaData.device.model = match[1];27 }28 // handle Samsung29 // 特殊型号可能以xxx-开头 或者直接空格接型号 兼容build结尾或直接)结尾30 // Galaxy nexus才是三星 nexus是google手机31 // 三星手机类型:galaxy xxx|SM-xxx|GT-xxx|SCH-xxx|SGH-xxx|SPH-xxx|SHW-xxx 若这些均未匹配到,则启用在中关村在线爬取到的机型白名单进行判断32 else if (match = ua.match(/[-\s](Galaxy[\s-_]nexus|Galaxy[\s-_]\w*[\s-_]\w*|Galaxy[\s-_]\w*|SM-\w*|GT-\w*|s[cgp]h-\w*|shw-\w*|ATIV|i9070|omnia|s7568|A3000|A3009|A5000|A5009|A7000|A7009|A8000|C101|C1116|C1158|E400|E500F|E7000|E7009|G3139D|G3502|G3502i|G3508|G3508J|G3508i|G3509|G3509i|G3558|G3559|G3568V|G3586V|G3589W|G3606|G3608|G3609|G3812|G388F|G5108|G5108Q|G5109|G5306W|G5308W|G5309W|G550|G600|G7106|G7108|G7108V|G7109|G7200|G720NO|G7508Q|G7509|G8508S|G8509V|G9006V|G9006W|G9008V|G9008W|G9009D|G9009W|G9198|G9200|G9208|G9209|G9250|G9280|I535|I679|I739|I8190N|I8262|I879|I879E|I889|I9000|I9060|I9082|I9082C|I9082i|I9100|I9100G|I9108|I9128|I9128E|I9128i|I9152|I9152P|I9158|I9158P|I9158V|I9168|I9168i|I9190|I9192|I9195|I9195I|I9200|I9208|I9220|I9228|I9260|I9268|I9300|I9300i|I9305|I9308|I9308i|I939|I939D|I939i|I9500|I9502|I9505|I9507V|I9508|I9508V|I959|J100|J110|J5008|J7008|N7100|N7102|N7105|N7108|N7108D|N719|N750|N7505|N7506V|N7508V|N7509V|N900|N9002|N9005|N9006|N9008|N9008S|N9008V|N9009|N9100|N9106W|N9108V|N9109W|N9150|N916|N9200|P709|P709E|P729|S6358|S7278|S7278U|S7562C|S7562i|S7898i|b9388)[\s\)]/i)) {33 uaData.device.manufacturer = 'Samsung';34 // 解决移动联通等不同发行版导致的机型不同问题35 // 特征:[A-Z]+[0-9]+[A-Z]*, 例如 G9006 G9006V 其实应该是G9006 另外三星只保留3位36 uaData.device.model = match[1].replace(/Galaxy S VI/i, 'Galaxy S6')37 .replace(/Galaxy S V/i, 'Galaxy S5')38 .replace(/Galaxy S IV/i, 'Galaxy S4')39 .replace(/Galaxy s III/i, 'Galaxy S3')40 .replace(/Galaxy S II/i, 'Galaxy S2')41 .replace(/Galaxy S I/i, 'Galaxy S1')42 .replace(/([a-z]+[0-9]{3})[0-9]?[a-z]*/i, '$1');43 }44 // 针对三星已经匹配出的数据做处理45 else if (uaData.device.manufacturer && uaData.device.manufacturer.toLowerCase() === 'samsung' && uaData.device.model) {46 uaData.device.model = uaData.device.model.replace(/Galaxy S VI/i, 'Galaxy S6')47 .replace(/Galaxy S V/i, 'Galaxy S5')48 .replace(/Galaxy S IV/i, 'Galaxy S4')49 .replace(/Galaxy s III/i, 'Galaxy S3')50 .replace(/Galaxy S II/i, 'Galaxy S2')51 .replace(/Galaxy S I/i, 'Galaxy S1')52 .replace(/([a-z]+[0-9]{3})[0-9]?[a-z]*/i, '$1');53 }54 // handle Huawei55 // 兼容build结尾或直接)结尾56 // 华为机型特征:Huawei[\s-_](\w*[-_]?\w*) 或者以 7D- ALE- CHE-等开头57 else if (match = ua.match(/(Huawei[\s-_](\w*[-_]?\w*)|\s(7D-\w*|ALE-\w*|ATH-\w*|CHE-\w*|CHM-\w*|Che1-\w*|Che2-\w*|D2-\w*|G616-\w*|G620S-\w*|G621-\w*|G660-\w*|G750-\w*|GRA-\w*|Hol-\w*|MT2-\w*|MT7-\w*|PE-\w*|PLK-\w*|SC-\w*|SCL-\w*|H60-\w*|H30-\w*)[\s\)])/i)) {58 uaData.device.manufacturer = 'Huawei';59 if (match[2]) {60 uaData.device.model = match[2];61 }62 else if (match[3]) {63 uaData.device.model = match[3];64 }65 // 解决移动联通等不同发行版导致的机型不同问题66 // 特征:xxx-[A-Z][0-9]+ 例如 H30-L01 H30-L00 H30-L20 都应该是 H30-L67 // h30-l h30-h h30-t 都是H3068 if (match = uaData.device.model.match(/(\w*)[\s-_]+[a-z0-9]+/i)) {69 uaData.device.model = match[1];70 }71 }72 // handle Xiaomi73 // 兼容build结尾或直接)结尾 以及特殊的HM处理方案(build/hm2013011)74 // xiaomi手机类型: mi m1 m2 m3 hm 开头75 // hongmi有特殊判断build/hm201501176 else if (match = ua.match(/;\s(mi|m1|m2|m3|m4|hm)(\s*\w*)[\s\)]/i)) {77 if (tmpMatch = ua.match(/(meitu|MediaPad)/i)) {78 // 美图手机名字冒充小米 比如 meitu m4 mizhi79 uaData.device.manufacturer = tmpMatch[1];80 uaData.device.model = '';81 }82 // 若匹配出的 match[2]没空格 会出现很多例如 mizi mizhi miha 但也会出现mi3 minote之类 特殊处理下83 else if (match[2].length > 0 && !((/\s/).test(match[2]))) {84 if (tmpMatch = match[2].match(/(\d)/i)) {85 uaData.device.model = match[1] + '-' + tmpMatch[1];86 }87 }88 else {89 uaData.device.manufacturer = 'Xiaomi';90 if (match[2] && match[2].length > 0) {91 match[2] = match[2].replace(/\s/, '');92 uaData.device.model = (match[1].substr(match[1].length - 2) + '-' + match[2]).replace(/m(\d)-/i, 'MI-$1');93 }94 else {95 uaData.device.model = (match[1].substr(match[1].length - 2)).replace(/m(\d)/i, 'MI-$1');96 }97 // 解决移动联通等不同发行版导致的机型不同问题98 // 特征:mi-3c,例如mi-4LTE mi-4 其实应该是 mi-499 if (/(mi|hm)(-\d)/i.test(uaData.device.model)) {100 // 看看是不是 MI-3S MI-4S....101 if (match = uaData.device.model.match(/(mi|hm)(-\ds)/i)) {102 uaData.device.model = match[1] + match[2];103 }104 // 防止 MI-20150XX等滥竽充数成为MI-2105 else if (match = uaData.device.model.match(/(mi|hm)(-\d{2})/i)) {106 uaData.device.model = match[1];107 }108 // 将mi-3c mi-3a mi-3w等合为mi-3109 else if (match = uaData.device.model.match(/(mi|hm)(-\d)[A-Z]/i)) {110 uaData.device.model = match[1] + match[2];111 }112 }113 // 去除 mi-4g这样的东西114 if (match = uaData.device.model.match(/(mi|hm)(-\dg)/i)) {115 uaData.device.model = match[1];116 }117 }118 }119 else if (/build\/HM\d{0,7}\)/i.test(ua)) {120 uaData.device.manufacturer = 'Xiaomi';121 uaData.device.model = 'HM';122 }123 else if (match = ua.match(/redmi\s?(\d+)?/i)) {124 uaData.device.manufacturer = 'Xiaomi';125 uaData.device.model = 'HM-' + match[1];126 }127 else if (uaData.device.manufacturer && uaData.device.manufacturer.toLowerCase() === 'xiaomi' && uaData.device.model) {128 // 针对通过base库判断出数据时命名风格不同。特殊处理适配如下129 if (match = uaData.device.model.match(/mi-one/i)) {130 uaData.device.model = 'MI-1';131 }132 // mi 2133 else if (match = uaData.device.model.match(/mi-two/i)) {134 uaData.device.model = 'MI-2';135 }136 // 20150xxx2014501137 else if (match = uaData.device.model.match(/\d{6}/i)) {138 uaData.device.model = '';139 }140 else if (match = uaData.device.model.match(/redmi/i)) {141 uaData.device.model = uaData.device.model.toUpperCase().replace(/redmi/i, 'HM');142 }143 // m1 m2 m3 写法不标准 另外判断是否是 m1-s144 else if (match = uaData.device.model.match(/(m\d)[\s-_](s?)/i)) {145 uaData.device.model = match[1].replace(/m/, 'MI-') + match[2];146 }147 // mi-2w mi-3w 等格式化为mi-2 mi-3148 else if (match = uaData.device.model.match(/(hm|mi)[\s-_](\d?)[a-rt-z]/i)) {149 if (tmpMatch = uaData.device.model.match(/(mi|hm)[\s-_](note|pad)(\d?s?)/i)) {150 uaData.device.model = tmpMatch[1] + '-' + tmpMatch[2] + tmpMatch[3];151 }152 else {153 uaData.device.model = match[2] ? match[1] + '-' + match[2] : match[1];154 }155 }156 // 处理hm157 else if (match = uaData.device.model.match(/hm/i)) {158 // 判断是不是 hm-201xxx充数159 if (match = uaData.device.model.match(/(hm)[\s-_](\d{2})/i)) {160 uaData.device.model = 'HM';161 }162 // 判断是不是 hm-2s hm-1s163 else if (match = uaData.device.model.match(/(hm)[\s-_](\ds)/i)) {164 uaData.device.model = 'HM-' + match[2];165 }166 else if (match = uaData.device.model.match(/(hm)[\s-_](\d)[a-z]/i)) {167 uaData.device.model = 'HM-' + match[2];168 }169 else {170 uaData.device.model = 'HM';171 }172 // 过滤类似 2g 3g等数据173 if (/hm-\dg/.test(uaData.device.model)) {174 uaData.device.model = 'HM';175 }176 }177 }178 // handle Vivo179 // 兼容build结尾或直接)结尾180 // vivo机型特征: Vivo[\s-_](\w*) 或者以 E1 S11t S7t 等开头181 else if (match = ua.match(/(vivo[\s-_](\w*)|\s(E1\w?|E3\w?|E5\w?|V1\w?|V2\w?|S11\w?|S12\w?|S1\w?|S3\w?|S6\w?|S7\w?|S9\w?|X1\w?|X3\w?|X520\w?|X5\w?|X5Max|X5Max+|X5Pro|X5SL|X710F|X710L|Xplay|Xshot|Xpaly3S|Y11\w?|Y11i\w?|Y11i\w?|Y13\w?|Y15\w?|Y17\w?|Y18\w?|Y19\w?|Y1\w?|Y20\w?|Y22\w?|Y22i\w?|Y23\w?|Y27\w?|Y28\w?|Y29\w?|Y33\w?|Y37\w?|Y3\w?|Y613\w?|Y622\w?|Y627\w?|Y913\w?|Y923\w?|Y927\w?|Y928\w?|Y929\w?|Y937\w?)[\s\)])/i)) {182 uaData.device.manufacturer = 'Vivo';183 uaData.device.model = match[1];184 // 首先剔除 viv- vivo- bbg- 等打头的内容185 uaData.device.model = uaData.device.model.replace(/(viv[\s-_]|vivo[\s-_]|bbg[\s-_])/i, '');186 // 解决移动联通等不同发行版导致的机型不同问题187 // 特征:[A-Z][0-9]+[A-Z] 例如 X5F X5L X5M X5iL 都应该是 X5188 if (match = uaData.device.model.match(/([a-z]+[0-9]+)i?[a-z]?[\s-_]?/i)) {189 uaData.device.model = match[1];190 }191 }192 // handle Oppo193 else if (match = ua.match(/(Oppo[\s-_](\w*)|\s(1100|1105|1107|3000|3005|3007|6607|A100|A103|A105|A105K|A109|A109K|A11|A113|A115|A115K|A121|A125|A127|A129|A201|A203|A209|A31|A31c|A31t|A31u|A51kc|A520|A613|A615|A617|E21W|Find|Mirror|N5110|N5117|N5207|N5209|R2010|R2017|R6007|R7005|R7007|R7c|R7t|R8000|R8007|R801|R805|R807|R809T|R8107|R8109|R811|R811W|R813T|R815T|R815W|R817|R819T|R8200|R8205|R8207|R821T|R823T|R827T|R830|R830S|R831S|R831T|R833T|R850|Real|T703|U2S|U521|U525|U529|U539|U701|U701T|U705T|U705W|X9000|X9007|X903|X905|X9070|X9077|X909|Z101|R829T)[\s\)])/i)) {194 uaData.device.manufacturer = 'Oppo';195 if (match[2]) {196 uaData.device.model = match[2];197 }198 else if (match[3]) {199 uaData.device.model = match[3];200 }201 // 解决移动联通等不同发行版导致的机型不同问题202 // 特征:[A-Z][0-9]+[A-Z] 例如 A31c A31s 都应该是 A31203 // 对 Plus 做特殊处理204 if (match = uaData.device.model.match(/([a-z]+[0-9]+)-?(plus)/i)) {205 uaData.device.model = match[1] + '-' + match[2];206 }207 else if (match = uaData.device.model.match(/(\w*-?[a-z]+[0-9]+)/i)) {208 uaData.device.model = match[1];209 }210 }211 else if (uaData.device.manufacturer && uaData.device.manufacturer.toLowerCase() === 'oppo' && uaData.device.model) {212 // 针对base库的数据做数据格式化处理213 // 解决移动联通等不同发行版导致的机型不同问题214 // 特征:[A-Z][0-9]+[A-Z] 例如 A31c A31s 都应该是 A31215 // 对 Plus 做特殊处理216 if (match = uaData.device.model.match(/([a-z]+[0-9]+)-?(plus)/i)) {217 uaData.device.model = match[1] + '-' + match[2];218 }219 else if (match = uaData.device.model.match(/(\w*-?[a-z]+[0-9]+)/i)) {220 uaData.device.model = match[1];221 }222 }223 // handle Lenovo224 // 兼容build结尾或直接)结尾 兼容Lenovo-xxx/xxx以及Leveno xxx build等225 else if (match = ua.match(/(Lenovo[\s-_](\w*[-_]?\w*)|\s(A3580|A3860|A5500|A5600|A5860|A7600|A806|A800|A808T|A808T-I|A936|A938t|A788t|K30-E|K30-T|K30-W|K50-T3s|K50-T5|K80M|K910|K910e|K920|S90-e|S90-t|S90-u|S968T|X2-CU|X2-TO|Z90-3|Z90-7)[\s\)])/i)) {226 uaData.device.manufacturer = 'Lenovo';227 if (match[2]) {228 uaData.device.model = match[2];229 }230 else if (match[3]) {231 uaData.device.model = match[3];232 }233 // 解决移动联通等不同发行版导致的机型不同问题234 // 特征:[A-Z][0-9]+[A-Z] 例如 A360t A360 都应该是 A360235 if (match = uaData.device.model.match(/([a-z]+[0-9]+)/i)) {236 uaData.device.model = match[1];237 }238 }239 // handle coolpad240 else if (match = ua.match(/(Coolpad[\s-_](\w*)|\s(7295C|7298A|7620L|8908|8085|8970L|9190L|Y80D)[\s\)])/i)) {241 uaData.device.manufacturer = 'Coolpad';242 if (match[2]) {243 uaData.device.model = match[2];244 }245 else if (match[3]) {246 uaData.device.model = match[3];247 }248 // 解决移动联通等不同发行版导致的机型不同问题249 // 特征:[A-Z][0-9]+[A-Z] 例如 8297-t01 8297-c01 8297w 都应该是 8297250 if (match = uaData.device.model.match(/([a-z]?[0-9]+)/i)) {251 uaData.device.model = match[1];252 }253 }254 else if (uaData.device.manufacturer && uaData.device.manufacturer.toLowerCase() === 'coolpad' && uaData.device.model) {255 // base 库适配256 // 解决移动联通等不同发行版导致的机型不同问题257 // 特征:[A-Z][0-9]+[A-Z] 例如 8297-t01 8297-c01 8297w 都应该是 8297258 if (match = uaData.device.model.match(/([a-z]?[0-9]+)/i)) {259 uaData.device.model = match[1];260 }261 }262 // handle meizu263 else if (match = ua.match(/\s(mx\d*\w*|mz-(\w*))\s(\w*)\s*\w*\s*build/i)) {264 uaData.device.manufacturer = 'Meizu';265 var tmpModel = match[2] ? match[2] : match[1];266 if (match[3]) {267 uaData.device.model = tmpModel + '-' + match[3];268 }269 else {270 uaData.device.model = tmpModel + '';271 }272 }273 else if (match = ua.match(/M463C|M35\d/i)) {274 uaData.device.manufacturer = 'Meizu';275 uaData.device.model = match[1];276 }277 // handle htc278 else if (match = ua.match(/(Htc[-_\s](\w*)|\s(601e|606w|608t|609d|610t|6160|619d|620G|626d|626s|626t|626w|709d|801e|802d|802t|802w|809D|816d|816e|816t|816v|816w|826d|826s|826t|826w|828w|901e|919d|A310e|A50AML|A510e|A620d|A620e|A620t|A810e|A9191|Aero|C620d|C620e|C620t|D316d|D516d|D516t|D516w|D820mt|D820mu|D820t|D820ts|D820u|D820us|E9pt|E9pw|E9sw|E9t|HD7S|M8Et|M8Sd|M8St|M8Sw|M8d|M8e|M8s|M8si|M8t|M8w|M9W|M9ew|Phablet|S510b|S510e|S610d|S710d|S710e|S720e|S720t|T327t|T328d|T328t|T328w|T329d|T329t|T329w|T528d|T528t|T528w|T8698|WF5w|X315e|X710e|X715e|X720d|X920e|Z560e|Z710e|Z710t|Z715e)[\s\)])/)) {279 uaData.device.manufacturer = 'Htc';280 uaData.device.model = match[1];281 }282 // handle Gionee283 else if (match = ua.match(/(Gionee[\s-_](\w*)|\s(GN\d+\w*)[\s\)])/i)) {284 uaData.device.manufacturer = 'Gionee';285 if (match[2]) {286 uaData.device.model = match[2];287 }288 else if (match[3]) {289 uaData.device.model = match[3];290 }291 }292 // handle LG293 else if (match = ua.match(/(LG[-_](\w*)|\s(D728|D729|D802|D855|D856|D857|D858|D859|E985T|F100L|F460|H778|H818|H819|P895|VW820)[\s\)])/i)) {294 uaData.device.manufacturer = 'Lg';295 if (match[2]) {296 uaData.device.model = match[2];297 }298 else if (match[3]) {299 uaData.device.model = match[3];300 }301 }302 // handle tcl303 else if (match = ua.match(/(Tcl[\s-_](\w*)|\s(H916T|P588L|P618L|P620M|P728M)[\s\)])/)) {304 uaData.device.manufacturer = 'Tcl';305 uaData.device.model = match[1];306 }307 // ZTE308 else if (match = ua.match(/(V9180|N918)/i)) {309 uaData.device.manufacturer = 'Zte';310 uaData.device.model = match[1];311 }312 else if (uaData.device.manufacturer && uaData.device.manufacturer.toLowerCase() === 'zte' && uaData.device.model) {313 // base 库适配314 // 解决移动联通等不同发行版导致的机型不同问题315 // 特征:[A-Z][0-9]+[A-Z] 例如 Q505T Q505u 都应该是 Q505316 if (match = uaData.device.model.match(/([a-z]?[0-9]+)/i)) {317 uaData.device.model = match[1];318 }319 }320 // UIMI321 else if (match = ua.match(/(UIMI\w*|umi\w*)[\s-_](\w*)\s*\w*\s*build/i)) {322 uaData.device.manufacturer = 'Uimi';323 if (match[2]) {324 uaData.device.model = match[1] + '-' + match[2];325 }326 else {327 uaData.device.model = match[1] + '';328 }329 }330 // eton331 else if (match = ua.match(/eton[\s-_](\w*)/i)) {332 uaData.device.manufacturer = 'Eton';333 uaData.device.model = match[1];334 }335 // Smartisan336 else if (match = ua.match(/(SM705|SM701|YQ601|YQ603)/i)) {337 uaData.device.manufacturer = 'Smartisan';338 uaData.device.model = ({339 SM705: 'T1',340 SM701: 'T1',341 YQ601: 'U1',342 YQ603: 'U1'343 })[match[1]] || match[1];344 }345 // handle Asus346 else if (match = ua.match(/(Asus[\s-_](\w*)|\s(A500CG|A500KL|A501CG|A600CG|PF400CG|PF500KL|T001|X002|X003|ZC500TG|ZE550ML|ZE551ML)[\s\)])/i)) {347 uaData.device.manufacturer = 'Asus';348 if (match[2]) {349 uaData.device.model = match[2];350 }351 else if (match[3]) {352 uaData.device.model = match[3];353 }354 }355 // handle nubia356 else if (match = ua.match(/(Nubia[-_\s](\w*)|(NX501|NX505J|NX506J|NX507J|NX503A|nx\d+\w*)[\s\)])/i)) {357 uaData.device.manufacturer = 'Nubia';358 if (match[2]) {359 uaData.device.model = match[2];360 }361 else if (match[3]) {362 uaData.device.model = match[3];363 }364 }365 // handle haier366 else if (match = ua.match(/(HT-\w*)|Haier[\s-_](\w*-?\w*)/i)) {367 uaData.device.manufacturer = 'Haier';368 if (match[1]) {369 uaData.device.model = match[1];370 }371 else if (match[2]) {372 uaData.device.model = match[2];373 }374 }375 // tianyu376 else if (match = ua.match(/K-Touch[\s-_](tou\s?ch\s?(\d)|\w*)/i)) {377 uaData.device.manufacturer = 'K-Touch';378 if (match[2]) {379 uaData.device.model = 'Ktouch' + match[2];380 }381 else {382 uaData.device.model = match[1];383 }384 }385 // DOOV386 else if (match = ua.match(/Doov[\s-_](\w*)/i)) {387 uaData.device.manufacturer = 'Doov';388 uaData.device.model = match[1];389 }390 // coobee391 else if (/koobee/i.test(ua)) {392 uaData.device.manufacturer = 'koobee';393 }394 // sony395 else if (/C69/i.test(ua)) {396 uaData.device.manufacturer = 'Sony';397 }398 // haojixing399 else if (/N787|N818S/i.test(ua)) {400 uaData.device.manufacturer = 'Haojixing';401 }402 // haisense403 else if (match = ua.match(/(hs-|Hisense[\s-_])(\w*)/i)) {404 uaData.device.manufacturer = 'Hisense';405 uaData.device.model = match[2];406 }407 // format the style of manufacturer408 if (uaData.device.manufacturer) {409 uaData.device.manufacturer = uaData.device.manufacturer.substr(0, 1).toUpperCase() + uaData.device.manufacturer.substr(1).toLowerCase();410 }411 // format the style of model412 if (uaData.device.model) {413 uaData.device.model = uaData.device.model.toUpperCase().replace(/-+|_+|\s+/g, ' ');414 uaData.device.model = uaData.device.model.match(/\s*(\w*\s*\w*)/)[1].replace(/\s+/, '-');415 // 针对三星、华为做去重的特殊处理416 if (uaData.device.manufacturer === 'Samsung') {417 uaData.device.model = ({418 'SCH-I95': 'GT-I950',419 'SCH-I93': 'GT-I930',420 'SCH-I86': 'GT-I855',421 'SCH-N71': 'GT-N710',422 'SCH-I73': 'GT-S789',423 'SCH-P70': 'GT-I915'424 })[uaData.device.model] || uaData.device.model;425 }426 else if (uaData.device.manufacturer === 'Huawei') {427 uaData.device.model = ({428 CHE1: 'CHE',429 CHE2: 'CHE',430 G620S: 'G621',431 C8817D: 'G621'432 })[uaData.device.model] || uaData.device.model;433 }434 }435 // 针对xiaomi 的部分数据没有格式化成功,格式化1次436 if (uaData.device.manufacturer && uaData.device.manufacturer === 'Xiaomi') {437 if (match = uaData.device.model.match(/(hm|mi)-(note)/i)) {438 uaData.device.model = match[1] + '-' + match[2];439 }440 else if (match = uaData.device.model.match(/(hm|mi)-(\ds?)/i)) {441 uaData.device.model = match[1] + '-' + match[2];442 }443 else if (match = uaData.device.model.match(/(hm|mi)-(\d)[a-rt-z]/i)) {444 uaData.device.model = match[1] + '-' + match[2];445 }446 }447 }448 // handle browser449 // if (!uaData.browser.name) {450 // ua = ua.toLowerCase();451 if (uaData.device.type === 'desktop') {452 if ( match = ua.match(/(Mac OS X [0-9\._]*)/i) ) {453 uaData.device.manufacturer = 'Apple';454 uaData.device.model = match[1];455 }456 /*457 * 360 security Explorer458 */459 if (match = /360se(?:[ \/]([\w.]+))?/i.exec(ua)) {460 uaData.browser.name = '360 security Explorer';461 uaData.browser.version = {462 original: match[1]463 };464 }465 /**466 * the world467 */468 else if (match = /the world(?:[ \/]([\w.]+))?/i.exec(ua)) {469 uaData.browser.name = 'the world';470 uaData.browser.version = {471 original: match[1]472 };473 }474 /**475 * tencenttraveler476 */477 else if (match = /tencenttraveler ([\w.]+)/i.exec(ua)) {478 uaData.browser.name = 'tencenttraveler';479 uaData.browser.version = {480 original: match[1]481 };482 }483 /**484 * LBBROWSER485 */486 else if (match = /LBBROWSER/i.exec(ua)) {487 uaData.browser.name = 'LBBROWSER';488 }489 }490 else if (uaData.device.type === 'mobile' || uaData.device.type === 'tablet') {491 /**492 * BaiduHD493 */494 if (match = /BaiduHD\s+([\w.]+)/i.exec(ua)) {495 uaData.browser.name = 'BaiduHD';496 uaData.browser.version = {497 original: match[1]498 };499 }500 /**501 * 360 Browser502 */503 else if (match = /360.s*aphone\s*browser\s*\(version\s*([\w.]+)\)/i.exec(ua)) {504 uaData.browser.name = '360 Browser';505 uaData.browser.version = {506 original: match[1]507 };508 }509 /**510 * Baidu Browser511 */512 else if (match = /flyflow\/([\w.]+)/i.exec(ua)) {513 uaData.browser.name = 'Baidu Browser';514 uaData.browser.version = {515 original: match[1]516 };517 }518 /**519 * Baidu HD520 */521 else if (match = /baiduhd ([\w.]+)/i.exec(ua)) {522 uaData.browser.name = 'Baidu HD';523 uaData.browser.version = {524 original: match[1]525 };526 }527 /**528 * baidubrowser529 */530 else if (match = /baidubrowser\/([\d\.]+)\s/i.exec(ua)) {531 uaData.browser.name = 'baidubrowser';532 uaData.browser.version = {533 original: match[1]534 };535 }536 /**537 * LieBaoFast538 */539 else if (match = /LieBaoFast\/([\w.]+)/i.exec(ua)) {540 uaData.browser.name = 'LieBao Fast';541 uaData.browser.version = {542 original: match[1]543 };544 }545 /**546 * LieBao547 */548 else if (match = /LieBao\/([\w.]+)/i.exec(ua)) {549 uaData.browser.name = 'LieBao';550 uaData.browser.version = {551 original: match[1]552 };553 }554 /**555 * SOUGOU556 */557 else if (match = /Sogou\w+\/([0-9\.]+)/i.exec(ua)) {558 uaData.browser.name = 'SogouMobileBrowser';559 uaData.browser.version = {560 original: match[1]561 };562 }563 /**564 * 百度国际565 */566 else if (match = /bdbrowser\w+\/([0-9\.]+)/i.exec(ua)) {567 uaData.browser.name = '百度国际';568 uaData.browser.version = {569 original: match[1]570 };571 }572 /**573 * Android Chrome Browser574 */575 else if (uaData.os.name === 'Android' && /safari/i.test(ua) && (match = /chrome\/([0-9\.]+)/i.exec(ua))) {576 if (tmpMatch = ua.match(/\s+(\w+Browser)\/?([\d\.]*)/)) {577 uaData.browser.name = tmpMatch[1];578 if (tmpMatch[2]) {579 uaData.browser.version = {original: tmpMatch[2]};580 } else {581 uaData.browser.version = {original: match[1]};582 }583 } else {584 uaData.browser.name = 'Android Chrome';585 uaData.browser.version = {original: match[1]};586 }587 }588 /**589 * Android Google Browser590 */591 else if (uaData.os.name === 'Android' && /safari/i.test(ua) && (match = /version\/([0-9\.]+)/i.exec(ua))) {592 if (tmpMatch = ua.match(/\s+(\w+Browser)\/?([\d\.]*)/)) {593 uaData.browser.name = tmpMatch[1];594 if (tmpMatch[2]) {595 uaData.browser.version = {original: tmpMatch[2]};596 } else {597 uaData.browser.version = {original: match[1]};598 }599 } else {600 uaData.browser.name = 'Android Browser';601 uaData.browser.version = {original: match[1]};602 }603 }604 /**605 * 'Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206' belongs to Safari606 */607 else if (/(ipad|iphone).* applewebkit\/.* mobile/i.test(ua)) {608 uaData.browser.name = 'Safari';609 }610 }611 if (match = ua.match(/baiduboxapp\/?([\d\.]*)/i)) {612 uaData.browser.name = '百度框';613 if (match[1]) {614 uaData.browser.version = {615 original: match[1]616 };617 }618 // uaData.browser.name = 'baidu box';619 }620 else if (/BaiduLightAppRuntime/i.test(ua)) {621 uaData.browser.name = '轻应用runtime';622 // uaData.browser.name = 'qing runtime';623 }624 else if (/Weibo/i.test(ua)) {625 uaData.browser.name = '微博';626 // uaData.browser.name = 'weibo';627 }628 else if (/MQQ/i.test(ua)) {629 uaData.browser.name = '手机QQ';630 // uaData.browser.name = 'mobile qq';631 }632 else if (/hao123/i.test(ua)) {633 uaData.browser.name = 'hao123';634 }635 // }636 if (match = /MicroMessenger\/([\w.]+)/i.exec(ua)) {637 uaData.browser.name = '微信';638 var tmpVersion = (match[1]).replace(/_/g, '.');639 tmpMatch = /(\d+\.\d+\.\d+\.\d+)/.exec(tmpVersion);640 if(tmpMatch) {641 tmpVersion = tmpMatch[1];642 }643 uaData.browser.version = {644 original: tmpVersion645 };646 }647 if (match = /UCBrowser\/([\w.]+)/i.exec(ua)) {648 uaData.browser.name = 'UC Browser';649 uaData.browser.version = {650 original: match[1]651 };652 }653 if (match = /OPR\/([\w.]+)/i.exec(ua)) {654 uaData.browser.name = 'Opera';655 uaData.browser.version = {656 original: match[1]657 };658 } else if (match = /OPiOS\/([\w.]+)/i.exec(ua)) {659 uaData.browser.name = 'Opera';660 uaData.browser.version = {661 original: match[1]662 };663 }664 // IE 11665 else if (/Trident\/7/i.test(ua) && /rv:11/i.test(ua)) {666 uaData.browser.name = 'Internet Explorer';667 uaData.browser.version = {668 major: '11',669 original: '11'670 };671 }672 // Microsoft Edge673 else if (/Edge\/12/i.test(ua) && /Windows Phone|Windows NT/i.test(ua)) {674 uaData.browser.name = 'Microsoft Edge';675 uaData.browser.version = {676 major: '12',677 original: '12'678 };679 }680 // miui browser681 else if (match = /miuibrowser\/([\w.]+)/i.exec(ua)) {682 uaData.browser.name = 'miui browser';683 uaData.browser.version = {684 original: match[1]685 };686 }687 // Safari688 if (!uaData.browser.name) {689 if (match = /Safari\/([\w.]+)/i.exec(ua) && /Version/i.test(ua)) {690 uaData.browser.name = 'Safari';691 }692 }693 if (uaData.browser.name && !uaData.browser.version) {694 if (match = /Version\/([\w.]+)/i.exec(ua)) {695 uaData.browser.version = {696 original: match[1]697 };698 }699 }700 // if (uaData.os.name === 'Windows' && uaData.os.version) {701 // // Windows 8.1702 // if (uaData.os.version.alias === 'NT 6.3') {703 // uaData.os.version.alias = '8.1';704 // }705 // }706 // handle os707 if (uaData.os.name === 'Windows' || /Windows/i.test(ua)) {708 uaData.os.name = 'Windows';709 if (/NT 6.3/i.test(ua)) {710 uaData.os.version = {711 alias: '8.1',712 original: '8.1'713 };714 }715 else if (/NT 6.4/i.test(ua) || /NT 10.0/i.test(ua)) {716 uaData.os.version = {717 alias: '10',718 original: '10'719 };720 }721 }722 else if (uaData.os.name === 'Mac OS X') {723 uaData.os.name = 'Mac OS X';724 if (match = /Mac OS X[\s\_\-\/](\d+[\.\-\_]\d+[\.\-\_]?\d*)/i.exec(ua)) {725 uaData.os.version = {726 alias: match[1].replace(/_/g, '.'),727 original: match[1].replace(/_/g, '.')728 };729 }730 else {731 uaData.os.version = {732 alias: '',733 original: ''734 };735 }736 }737 else if (/Android/i.test(uaData.os.name)) {738 if (match = ua.match(/Android[\s\_\-\/i686]?[\s\_\-\/](\d+[\.\-\_]\d+[\.\-\_]?\d*)/i)) {739 uaData.os.version = {740 alias: match[1],741 original: match[1]742 };743 }744 }745 return uaData;...

Full Screen

Full Screen

ua-device.js

Source:ua-device.js Github

copy

Full Screen

1function getUA(ua) {2 var uaData = new UA(ua);3 var match;4 var tmpMatch;5 // handle mobile device6 if (uaData.device.type === 'mobile' || uaData.device.type === 'tablet') {7 // get manufacturer through the key words8 if (match = ua.match(/(ZTE|Samsung|Motorola|HTC|Coolpad|Huawei|Lenovo|LG|Sony Ericsson|Oppo|TCL|Vivo|Sony|Meizu|Nokia)/i)) {9 uaData.device.manufacturer = match[1];10 if (uaData.device.model && uaData.device.model.indexOf(match[1]) >= 0) {11 uaData.device.model = uaData.device.model.replace(match[1], '');12 }13 }14 // handle Apple15 // 苹果就这3种iPod iPad iPhone16 if (match = ua.match(/(iPod|iPad|iPhone)/i)) {17 uaData.device.manufacturer = 'Apple';18 uaData.device.model = match[1];19 }20 // handle Samsung21 // 特殊型号可能以xxx-开头 或者直接空格接型号 兼容build结尾或直接)结尾22 // Galaxy nexus才是三星 nexus是google手机23 // 三星手机类型:galaxy xxx|SM-xxx|GT-xxx|SCH-xxx|SGH-xxx|SPH-xxx|SHW-xxx 若这些均未匹配到,则启用在中关村在线爬取到的机型白名单进行判断24 else if (match = ua.match(/[-\s](Galaxy[\s-_]nexus|Galaxy[\s-_]\w*[\s-_]\w*|Galaxy[\s-_]\w*|SM-\w*|GT-\w*|s[cgp]h-\w*|shw-\w*|ATIV|i9070|omnia|s7568|A3000|A3009|A5000|A5009|A7000|A7009|A8000|C101|C1116|C1158|E400|E500F|E7000|E7009|G3139D|G3502|G3502i|G3508|G3508J|G3508i|G3509|G3509i|G3558|G3559|G3568V|G3586V|G3589W|G3606|G3608|G3609|G3812|G388F|G5108|G5108Q|G5109|G5306W|G5308W|G5309W|G550|G600|G7106|G7108|G7108V|G7109|G7200|G720NO|G7508Q|G7509|G8508S|G8509V|G9006V|G9006W|G9008V|G9008W|G9009D|G9009W|G9198|G9200|G9208|G9209|G9250|G9280|I535|I679|I739|I8190N|I8262|I879|I879E|I889|I9000|I9060|I9082|I9082C|I9082i|I9100|I9100G|I9108|I9128|I9128E|I9128i|I9152|I9152P|I9158|I9158P|I9158V|I9168|I9168i|I9190|I9192|I9195|I9195I|I9200|I9208|I9220|I9228|I9260|I9268|I9300|I9300i|I9305|I9308|I9308i|I939|I939D|I939i|I9500|I9502|I9505|I9507V|I9508|I9508V|I959|J100|J110|J5008|J7008|N7100|N7102|N7105|N7108|N7108D|N719|N750|N7505|N7506V|N7508V|N7509V|N900|N9002|N9005|N9006|N9008|N9008S|N9008V|N9009|N9100|N9106W|N9108V|N9109W|N9150|N916|N9200|P709|P709E|P729|S6358|S7278|S7278U|S7562C|S7562i|S7898i|b9388)[\s\)]/i)) {25 uaData.device.manufacturer = 'Samsung';26 // 解决移动联通等不同发行版导致的机型不同问题27 // 特征:[A-Z]+[0-9]+[A-Z]*, 例如 G9006 G9006V 其实应该是G9006 另外三星只保留3位28 uaData.device.model = match[1].replace(/Galaxy S VI/i, 'Galaxy S6')29 .replace(/Galaxy S V/i, 'Galaxy S5')30 .replace(/Galaxy S IV/i, 'Galaxy S4')31 .replace(/Galaxy s III/i, 'Galaxy S3')32 .replace(/Galaxy S II/i, 'Galaxy S2')33 .replace(/Galaxy S I/i, 'Galaxy S1')34 .replace(/([a-z]+[0-9]{3})[0-9]?[a-z]*/i, '$1');35 }36 // 针对三星已经匹配出的数据做处理37 else {38 if (uaData.device.manufacturer && uaData.device.manufacturer.toLowerCase() === 'samsung' && uaData.device.model) {39 uaData.device.model = uaData.device.model.replace(/Galaxy S VI/i, 'Galaxy S6')40 .replace(/Galaxy S V/i, 'Galaxy S5')41 .replace(/Galaxy S IV/i, 'Galaxy S4')42 .replace(/Galaxy s III/i, 'Galaxy S3')43 .replace(/Galaxy S II/i, 'Galaxy S2')44 .replace(/Galaxy S I/i, 'Galaxy S1')45 .replace(/([a-z]+[0-9]{3})[0-9]?[a-z]*/i, '$1');46 }47 // handle Huawei48 // 兼容build结尾或直接)结尾49 // 华为机型特征:Huawei[\s-_](\w*[-_]?\w*) 或者以 7D- ALE- CHE-等开头50 else if (match = ua.match(/(Huawei[\s-_](\w*[-_]?\w*)|\s(7D-\w*|ALE-\w*|ATH-\w*|CHE-\w*|CHM-\w*|Che1-\w*|Che2-\w*|D2-\w*|G616-\w*|G620S-\w*|G621-\w*|G660-\w*|G750-\w*|GRA-\w*|Hol-\w*|MT2-\w*|MT7-\w*|PE-\w*|PLK-\w*|SC-\w*|SCL-\w*|H60-\w*|H30-\w*)[\s\)])/i)) {51 uaData.device.manufacturer = 'Huawei';52 if (match[2]) {53 uaData.device.model = match[2];54 }55 else if (match[3]) {56 uaData.device.model = match[3];57 }58 // 解决移动联通等不同发行版导致的机型不同问题59 // 特征:xxx-[A-Z][0-9]+ 例如 H30-L01 H30-L00 H30-L20 都应该是 H30-L60 // h30-l h30-h h30-t 都是H3061 if (match = uaData.device.model.match(/(\w*)[\s-_]+[a-z0-9]+/i)) {62 uaData.device.model = match[1];63 }64 }65 // handle Xiaomi66 // 兼容build结尾或直接)结尾 以及特殊的HM处理方案(build/hm2013011)67 // xiaomi手机类型: mi m1 m2 m3 hm 开头68 // hongmi有特殊判断build/hm201501169 else if (match = ua.match(/;\s(mi|m1|m2|m3|m4|hm)(\s*\w*)[\s\)]/i)) {70 if (tmpMatch = ua.match(/(meitu|MediaPad)/i)) {71 // 美图手机名字冒充小米 比如 meitu m4 mizhi72 uaData.device.manufacturer = tmpMatch[1];73 uaData.device.model = '';74 }75 // 若匹配出的 match[2]没空格 会出现很多例如 mizi mizhi miha 但也会出现mi3 minote之类 特殊处理下76 else if (match[2].length > 0 && !((/\s/).test(match[2]))) {77 if (tmpMatch = match[2].match(/(\d)/i)) {78 uaData.device.model = match[1] + '-' + tmpMatch[1];79 }80 }81 else {82 uaData.device.manufacturer = 'Xiaomi';83 if (match[2] && match[2].length > 0) {84 match[2] = match[2].replace(/\s/, '');85 uaData.device.model = (match[1].substr(match[1].length - 2) + '-' + match[2]).replace(/m(\d)-/i, 'MI-$1');86 }87 else {88 uaData.device.model = (match[1].substr(match[1].length - 2)).replace(/m(\d)/i, 'MI-$1');89 }90 // 解决移动联通等不同发行版导致的机型不同问题91 // 特征:mi-3c,例如mi-4LTE mi-4 其实应该是 mi-492 if (/(mi|hm)(-\d)/i.test(uaData.device.model)) {93 // 看看是不是 MI-3S MI-4S....94 if (match = uaData.device.model.match(/(mi|hm)(-\ds)/i)) {95 uaData.device.model = match[1] + match[2];96 }97 // 防止 MI-20150XX等滥竽充数成为MI-298 else if (match = uaData.device.model.match(/(mi|hm)(-\d{2})/i)) {99 uaData.device.model = match[1];100 }101 // 将mi-3c mi-3a mi-3w等合为mi-3102 else if (match = uaData.device.model.match(/(mi|hm)(-\d)[A-Z]/i)) {103 uaData.device.model = match[1] + match[2];104 }105 }106 // 去除 mi-4g这样的东西107 if (match = uaData.device.model.match(/(mi|hm)(-\dg)/i)) {108 uaData.device.model = match[1];109 }110 }111 }112 else if (/build\/HM\d{0,7}\)/i.test(ua)) {113 uaData.device.manufacturer = 'Xiaomi';114 uaData.device.model = 'HM';115 }116 else if (uaData.device.manufacturer && uaData.device.manufacturer.toLowerCase() === 'xiaomi' && uaData.device.model) {117 // 针对通过base库判断出数据时命名风格不同。特殊处理适配如下118 if (match = uaData.device.model.match(/mi-one/i)) {119 uaData.device.model = 'MI-1';120 }121 // mi 2122 else if (match = uaData.device.model.match(/mi-two/i)) {123 uaData.device.model = 'MI-2';124 }125 // 20150xxx2014501126 else if (match = uaData.device.model.match(/\d{6}/i)) {127 uaData.device.model = '';128 }129 else if (match = uaData.device.model.match(/redmi/i)) {130 uaData.device.model = uaData.device.model.toUpperCase().replace(/redmi/i, 'HM');131 }132 // m1 m2 m3 写法不标准 另外判断是否是 m1-s133 else if (match = uaData.device.model.match(/(m\d)[\s-_](s?)/i)) {134 uaData.device.model = match[1].replace(/m/, 'MI-') + match[2];135 }136 // mi-2w mi-3w 等格式化为mi-2 mi-3137 else if (match = uaData.device.model.match(/(hm|mi)[\s-_](\d?)[a-rt-z]/i)) {138 if (tmpMatch = uaData.device.model.match(/(mi|hm)[\s-_](note|pad)(\d?s?)/i)) {139 uaData.device.model = tmpMatch[1] + '-' + tmpMatch[2] + tmpMatch[3];140 }141 else {142 uaData.device.model = match[2] ? match[1] + '-' + match[2] : match[1];143 }144 }145 // 处理hm146 else if (match = uaData.device.model.match(/hm/i)) {147 // 判断是不是 hm-201xxx充数148 if (match = uaData.device.model.match(/(hm)[\s-_](\d{2})/i)) {149 uaData.device.model = 'HM';150 }151 // 判断是不是 hm-2s hm-1s152 else if (match = uaData.device.model.match(/(hm)[\s-_](\ds)/i)) {153 uaData.device.model = 'HM-' + match[2];154 }155 else if (match = uaData.device.model.match(/(hm)[\s-_](\d)[a-z]/i)) {156 uaData.device.model = 'HM-' + match[2];157 }158 else {159 uaData.device.model = 'HM';160 }161 // 过滤类似 2g 3g等数据162 if (/hm-\dg/.test(uaData.device.model)) {163 uaData.device.model = 'HM';164 }165 }166 }167 // handle Vivo168 // 兼容build结尾或直接)结尾169 // vivo机型特征: Vivo[\s-_](\w*) 或者以 E1 S11t S7t 等开头170 else if (match = ua.match(/(vivo[\s-_](\w*)|\s(E1\w?|E3\w?|E5\w?|V1\w?|V2\w?|S11\w?|S12\w?|S1\w?|S3\w?|S6\w?|S7\w?|S9\w?|X1\w?|X3\w?|X520\w?|X5\w?|X5Max|X5Max+|X5Pro|X5SL|X710F|X710L|Xplay|Xshot|Xpaly3S|Y11\w?|Y11i\w?|Y11i\w?|Y13\w?|Y15\w?|Y17\w?|Y18\w?|Y19\w?|Y1\w?|Y20\w?|Y22\w?|Y22i\w?|Y23\w?|Y27\w?|Y28\w?|Y29\w?|Y33\w?|Y37\w?|Y3\w?|Y613\w?|Y622\w?|Y627\w?|Y913\w?|Y923\w?|Y927\w?|Y928\w?|Y929\w?|Y937\w?)[\s\)])/i)) {171 uaData.device.manufacturer = 'Vivo';172 uaData.device.model = match[1];173 // 首先剔除 viv- vivo- bbg- 等打头的内容174 uaData.device.model = uaData.device.model.replace(/(viv[\s-_]|vivo[\s-_]|bbg[\s-_])/i, '');175 // 解决移动联通等不同发行版导致的机型不同问题176 // 特征:[A-Z][0-9]+[A-Z] 例如 X5F X5L X5M X5iL 都应该是 X5177 if (match = uaData.device.model.match(/([a-z]+[0-9]+)i?[a-z]?[\s-_]?/i)) {178 uaData.device.model = match[1];179 }180 }181 // handle Oppo182 else if (match = ua.match(/(Oppo[\s-_](\w*)|\s(1100|1105|1107|3000|3005|3007|6607|A100|A103|A105|A105K|A109|A109K|A11|A113|A115|A115K|A121|A125|A127|A129|A201|A203|A209|A31|A31c|A31t|A31u|A51kc|A520|A613|A615|A617|E21W|Find|Mirror|N5110|N5117|N5207|N5209|R2010|R2017|R6007|R7005|R7007|R7c|R7t|R8000|R8007|R801|R805|R807|R809T|R8107|R8109|R811|R811W|R813T|R815T|R815W|R817|R819T|R8200|R8205|R8207|R821T|R823T|R827T|R830|R830S|R831S|R831T|R833T|R850|Real|T703|U2S|U521|U525|U529|U539|U701|U701T|U705T|U705W|X9000|X9007|X903|X905|X9070|X9077|X909|Z101|R829T)[\s\)])/i)) {183 uaData.device.manufacturer = 'Oppo';184 if (match[2]) {185 uaData.device.model = match[2];186 }187 else if (match[3]) {188 uaData.device.model = match[3];189 }190 // 解决移动联通等不同发行版导致的机型不同问题191 // 特征:[A-Z][0-9]+[A-Z] 例如 A31c A31s 都应该是 A31192 // 对 Plus 做特殊处理193 if (match = uaData.device.model.match(/([a-z]+[0-9]+)-?(plus)/i)) {194 uaData.device.model = match[1] + '-' + match[2];195 }196 else if (match = uaData.device.model.match(/(\w*-?[a-z]+[0-9]+)/i)) {197 uaData.device.model = match[1];198 }199 }200 else if (uaData.device.manufacturer && uaData.device.manufacturer.toLowerCase() === 'oppo' && uaData.device.model) {201 // 针对base库的数据做数据格式化处理202 // 解决移动联通等不同发行版导致的机型不同问题203 // 特征:[A-Z][0-9]+[A-Z] 例如 A31c A31s 都应该是 A31204 // 对 Plus 做特殊处理205 if (match = uaData.device.model.match(/([a-z]+[0-9]+)-?(plus)/i)) {206 uaData.device.model = match[1] + '-' + match[2];207 }208 else if (match = uaData.device.model.match(/(\w*-?[a-z]+[0-9]+)/i)) {209 uaData.device.model = match[1];210 }211 }212 // handle Lenovo213 // 兼容build结尾或直接)结尾 兼容Lenovo-xxx/xxx以及Leveno xxx build等214 else if (match = ua.match(/(Lenovo[\s-_](\w*[-_]?\w*)|\s(A3580|A3860|A5500|A5600|A5860|A7600|A806|A800|A808T|A808T-I|A936|A938t|A788t|K30-E|K30-T|K30-W|K50-T3s|K50-T5|K80M|K910|K910e|K920|S90-e|S90-t|S90-u|S968T|X2-CU|X2-TO|Z90-3|Z90-7)[\s\)])/i)) {215 uaData.device.manufacturer = 'Lenovo';216 if (match[2]) {217 uaData.device.model = match[2];218 }219 else if (match[3]) {220 uaData.device.model = match[3];221 }222 // 解决移动联通等不同发行版导致的机型不同问题223 // 特征:[A-Z][0-9]+[A-Z] 例如 A360t A360 都应该是 A360224 if (match = uaData.device.model.match(/([a-z]+[0-9]+)/i)) {225 uaData.device.model = match[1];226 }227 }228 // handle coolpad229 else if (match = ua.match(/(Coolpad[\s-_](\w*)|\s(7295C|7298A|7620L|8908|8085|8970L|9190L|Y80D)[\s\)])/i)) {230 uaData.device.manufacturer = 'Coolpad';231 if (match[2]) {232 uaData.device.model = match[2];233 }234 else if (match[3]) {235 uaData.device.model = match[3];236 }237 // 解决移动联通等不同发行版导致的机型不同问题238 // 特征:[A-Z][0-9]+[A-Z] 例如 8297-t01 8297-c01 8297w 都应该是 8297239 if (match = uaData.device.model.match(/([a-z]?[0-9]+)/i)) {240 uaData.device.model = match[1];241 }242 }243 else if (uaData.device.manufacturer && uaData.device.manufacturer.toLowerCase() === 'coolpad' && uaData.device.model) {244 // base 库适配245 // 解决移动联通等不同发行版导致的机型不同问题246 // 特征:[A-Z][0-9]+[A-Z] 例如 8297-t01 8297-c01 8297w 都应该是 8297247 if (match = uaData.device.model.match(/([a-z]?[0-9]+)/i)) {248 uaData.device.model = match[1];249 }250 }251 // handle meizu252 else if (match = ua.match(/\s(mx\d*\w*|mz-(\w*))\s(\w*)\s*\w*\s*build/i)) {253 uaData.device.manufacturer = 'Meizu';254 var tmpModel = match[2] ? match[2] : match[1];255 if (match[3]) {256 uaData.device.model = tmpModel + '-' + match[3];257 }258 else {259 uaData.device.model = tmpModel + '';260 }261 }262 else if (match = ua.match(/M463C|M35\d/i)) {263 uaData.device.manufacturer = 'Meizu';264 uaData.device.model = match[1];265 }266 // handle htc267 else if (match = ua.match(/(Htc[-_\s](\w*)|\s(601e|606w|608t|609d|610t|6160|619d|620G|626d|626s|626t|626w|709d|801e|802d|802t|802w|809D|816d|816e|816t|816v|816w|826d|826s|826t|826w|828w|901e|919d|A310e|A50AML|A510e|A620d|A620e|A620t|A810e|A9191|Aero|C620d|C620e|C620t|D316d|D516d|D516t|D516w|D820mt|D820mu|D820t|D820ts|D820u|D820us|E9pt|E9pw|E9sw|E9t|HD7S|M8Et|M8Sd|M8St|M8Sw|M8d|M8e|M8s|M8si|M8t|M8w|M9W|M9ew|Phablet|S510b|S510e|S610d|S710d|S710e|S720e|S720t|T327t|T328d|T328t|T328w|T329d|T329t|T329w|T528d|T528t|T528w|T8698|WF5w|X315e|X710e|X715e|X720d|X920e|Z560e|Z710e|Z710t|Z715e)[\s\)])/)) {268 uaData.device.manufacturer = 'Htc';269 uaData.device.model = match[1];270 }271 // handle Gionee272 else if (match = ua.match(/(Gionee[\s-_](\w*)|\s(GN\d+\w*)[\s\)])/i)) {273 uaData.device.manufacturer = 'Gionee';274 if (match[2]) {275 uaData.device.model = match[2];276 }277 else if (match[3]) {278 uaData.device.model = match[3];279 }280 }281 // handle LG282 else if (match = ua.match(/(LG[-_](\w*)|\s(D728|D729|D802|D855|D856|D857|D858|D859|E985T|F100L|F460|H778|H818|H819|P895|VW820)[\s\)])/i)) {283 uaData.device.manufacturer = 'Lg';284 if (match[2]) {285 uaData.device.model = match[2];286 }287 else if (match[3]) {288 uaData.device.model = match[3];289 }290 }291 // handle tcl292 else if (match = ua.match(/(Tcl[\s-_](\w*)|\s(H916T|P588L|P618L|P620M|P728M)[\s\)])/)) {293 uaData.device.manufacturer = 'Tcl';294 uaData.device.model = match[1];295 }296 // ZTE297 else if (match = ua.match(/(V9180|N918)/i)) {298 uaData.device.manufacturer = 'Zte';299 uaData.device.model = match[1];300 }301 else if (uaData.device.manufacturer && uaData.device.manufacturer.toLowerCase() === 'zte' && uaData.device.model) {302 // base 库适配303 // 解决移动联通等不同发行版导致的机型不同问题304 // 特征:[A-Z][0-9]+[A-Z] 例如 Q505T Q505u 都应该是 Q505305 if (match = uaData.device.model.match(/([a-z]?[0-9]+)/i)) {306 uaData.device.model = match[1];307 }308 }309 // UIMI310 else if (match = ua.match(/(UIMI\w*|umi\w*)[\s-_](\w*)\s*\w*\s*build/i)) {311 uaData.device.manufacturer = 'Uimi';312 if (match[2]) {313 uaData.device.model = match[1] + '-' + match[2];314 }315 else {316 uaData.device.model = match[1] + '';317 }318 }319 // eton320 else if (match = ua.match(/eton[\s-_](\w*)/i)) {321 uaData.device.manufacturer = 'Eton';322 uaData.device.model = match[1];323 }324 // Smartisan325 else if (match = ua.match(/(SM705|SM701|YQ601|YQ603)/i)) {326 uaData.device.manufacturer = 'Smartisan';327 uaData.device.model = ({328 SM705: 'T1',329 SM701: 'T1',330 YQ601: 'U1',331 YQ603: 'U1'332 })[match[1]] || match[1];333 }334 // handle Asus335 else if (match = ua.match(/(Asus[\s-_](\w*)|\s(A500CG|A500KL|A501CG|A600CG|PF400CG|PF500KL|T001|X002|X003|ZC500TG|ZE550ML|ZE551ML)[\s\)])/i)) {336 uaData.device.manufacturer = 'Asus';337 if (match[2]) {338 uaData.device.model = match[2];339 }340 else if (match[3]) {341 uaData.device.model = match[3];342 }343 }344 // handle nubia345 else if (match = ua.match(/(Nubia[-_\s](\w*)|(NX501|NX505J|NX506J|NX507J|NX503A|nx\d+\w*)[\s\)])/i)) {346 uaData.device.manufacturer = 'Nubia';347 if (match[2]) {348 uaData.device.model = match[2];349 }350 else if (match[3]) {351 uaData.device.model = match[3];352 }353 }354 // handle haier355 else if (match = ua.match(/(HT-\w*)|Haier[\s-_](\w*-?\w*)/i)) {356 uaData.device.manufacturer = 'Haier';357 if (match[1]) {358 uaData.device.model = match[1];359 }360 else if (match[2]) {361 uaData.device.model = match[2];362 }363 }364 // tianyu365 else if (match = ua.match(/K-Touch[\s-_](tou\s?ch\s?(\d)|\w*)/i)) {366 uaData.device.manufacturer = 'K-Touch';367 if (match[2]) {368 uaData.device.model = 'Ktouch' + match[2];369 }370 else {371 uaData.device.model = match[1];372 }373 }374 // DOOV375 else if (match = ua.match(/Doov[\s-_](\w*)/i)) {376 uaData.device.manufacturer = 'Doov';377 uaData.device.model = match[1];378 }379 // coobee380 else if (/koobee/i.test(ua)) {381 uaData.device.manufacturer = 'koobee';382 }383 // sony384 else if (/C69/i.test(ua)) {385 uaData.device.manufacturer = 'Sony';386 }387 // haojixing388 else if (/N787|N818S/i.test(ua)) {389 uaData.device.manufacturer = 'Haojixing';390 }391 // haisense392 else if (match = ua.match(/(hs-|Hisense[\s-_])(\w*)/i)) {393 uaData.device.manufacturer = 'Hisense';394 uaData.device.model = match[2];395 }396 }397 // format the style of manufacturer398 if (uaData.device.manufacturer) {399 uaData.device.manufacturer = uaData.device.manufacturer.substr(0, 1).toUpperCase() + uaData.device.manufacturer.substr(1).toLowerCase();400 }401 // format the style of model402 if (uaData.device.model) {403 uaData.device.model = uaData.device.model.toUpperCase().replace(/-+|_+|\s+/g, ' ');404 uaData.device.model = uaData.device.model.match(/\s*(\w*\s*\w*)/)[1].replace(/\s+/, '-');405 // 针对三星、华为做去重的特殊处理406 if (uaData.device.manufacturer === 'Samsung') {407 uaData.device.model = ({408 'SCH-I95': 'GT-I950',409 'SCH-I93': 'GT-I930',410 'SCH-I86': 'GT-I855',411 'SCH-N71': 'GT-N710',412 'SCH-I73': 'GT-S789',413 'SCH-P70': 'GT-I915'414 })[uaData.device.model] || uaData.device.model;415 }416 else if (uaData.device.manufacturer === 'Huawei') {417 uaData.device.model = ({418 CHE1: 'CHE',419 CHE2: 'CHE',420 G620S: 'G621',421 C8817D: 'G621'422 })[uaData.device.model] || uaData.device.model;423 }424 }425 // 针对xiaomi 的部分数据没有格式化成功,格式化1次426 if (uaData.device.manufacturer && uaData.device.manufacturer === 'Xiaomi') {427 if (match = uaData.device.model.match(/(hm|mi)-(note)/i)) {428 uaData.device.model = match[1] + '-' + match[2];429 }430 else if (match = uaData.device.model.match(/(hm|mi)-(\ds?)/i)) {431 uaData.device.model = match[1] + '-' + match[2];432 }433 else if (match = uaData.device.model.match(/(hm|mi)-(\d)[a-rt-z]/i)) {434 uaData.device.model = match[1] + '-' + match[2];435 }436 }437 }438 // handle browser439 // if (!uaData.browser.name) {440 // ua = ua.toLowerCase();441 if (uaData.device.type === 'desktop') {442 /*443 * 360 security Explorer444 */445 if (match = /360se(?:[ \/]([\w.]+))?/i.exec(ua)) {446 uaData.browser.name = '360 security Explorer';447 uaData.browser.version = {448 original: match[1]449 };450 }451 /**452 * the world453 */454 else if (match = /the world(?:[ \/]([\w.]+))?/i.exec(ua)) {455 uaData.browser.name = 'the world';456 uaData.browser.version = {457 original: match[1]458 };459 }460 /**461 * tencenttraveler462 */463 else if (match = /tencenttraveler ([\w.]+)/i.exec(ua)) {464 uaData.browser.name = 'tencenttraveler';465 uaData.browser.version = {466 original: match[1]467 };468 }469 }470 else if (uaData.device.type === 'mobile' || uaData.device.type === 'tablet') {471 /**472 * BaiduHD473 */474 if (match = /BaiduHD\s+([\w.]+)/i.exec(ua)) {475 uaData.browser.name = 'BaiduHD';476 uaData.browser.version = {477 original: match[1]478 };479 }480 /**481 * 360 Browser482 */483 else if (match = /360.s*aphone\s*browser\s*\(version\s*([\w.]+)\)/i.exec(ua)) {484 uaData.browser.name = '360 Browser';485 uaData.browser.version = {486 original: match[1]487 };488 }489 /**490 * Baidu Browser491 */492 else if (match = /flyflow\/([\w.]+)/i.exec(ua)) {493 uaData.browser.name = 'Baidu Browser';494 uaData.browser.version = {495 original: match[1]496 };497 }498 /**499 * Baidu HD500 */501 else if (match = /baiduhd ([\w.]+)/i.exec(ua)) {502 uaData.browser.name = 'Baidu HD';503 uaData.browser.version = {504 original: match[1]505 };506 }507 /**508 * LieBaoFast509 */510 else if (match = /LieBaoFast\/([\w.]+)/i.exec(ua)) {511 uaData.browser.name = 'LieBao Fast';512 uaData.browser.version = {513 original: match[1]514 };515 }516 /**517 * LieBao518 */519 else if (match = /LieBao\/([\w.]+)/i.exec(ua)) {520 uaData.browser.name = 'LieBao';521 uaData.browser.version = {522 original: match[1]523 };524 }525 /**526 * Android Google Browser527 */528 else if (uaData.os.name === 'Android' && /safari/i.test(ua) && (match = /version\/([0-9\.]+)/i.exec(ua))) {529 uaData.browser.name = 'Google Browser';530 uaData.browser.version = {original: match[1]};531 }532 /**533 * 'Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206' belongs to Safari534 */535 else if (/(ipad|iphone).* applewebkit\/.* mobile/i.test(ua)) {536 uaData.browser.name = 'Safari';537 }538 }539 if (/baiduboxapp/i.test(ua)) {540 uaData.browser.name = '百度框';541 // uaData.browser.name = 'baidu box';542 }543 else if (/BaiduLightAppRuntime/i.test(ua)) {544 uaData.browser.name = '轻应用runtime';545 // uaData.browser.name = 'qing runtime';546 }547 else if (/Weibo/i.test(ua)) {548 uaData.browser.name = '微博';549 // uaData.browser.name = 'weibo';550 }551 else if (/MQQ/i.test(ua)) {552 uaData.browser.name = '手机QQ';553 // uaData.browser.name = 'mobile qq';554 }555 else if (/hao123/i.test(ua)) {556 uaData.browser.name = 'hao123';557 }558 // }559 if (match = /MicroMessenger\/([\w.]+)/i.exec(ua)) {560 uaData.browser.name = '微信';561 var tmpVersion = (match[1]).replace(/_/g, '.');562 tmpMatch = /(\d+\.\d+\.\d+\.\d+)/.exec(tmpVersion);563 if (tmpMatch) {564 tmpVersion = tmpMatch[1];565 }566 uaData.browser.version = {567 original: tmpVersion568 };569 }570 if (match = /UCBrowser\/([\w.]+)/i.exec(ua)) {571 uaData.browser.name = 'UC Browser';572 uaData.browser.version = {573 original: match[1]574 };575 }576 if (match = /OPR\/([\w.]+)/i.exec(ua)) {577 uaData.browser.name = 'Opera';578 uaData.browser.version = {579 original: match[1]580 };581 }582 // IE 11583 else if (/Trident\/7/i.test(ua) && /rv:11/i.test(ua)) {584 uaData.browser.name = 'Internet Explorer';585 uaData.browser.version = {586 major: '11',587 original: '11'588 };589 }590 // Microsoft Edge591 else if (/Edge\/12/i.test(ua) && /Windows Phone|Windows NT/i.test(ua)) {592 uaData.browser.name = 'Microsoft Edge';593 uaData.browser.version = {594 major: '12',595 original: '12'596 };597 }598 // miui browser599 else if (match = /miuibrowser\/([\w.]+)/i.exec(ua)) {600 uaData.browser.name = 'miui browser';601 uaData.browser.version = {602 original: match[1]603 };604 }605 // Safari606 if (!uaData.browser.name) {607 if (match = /Safari\/([\w.]+)/i.exec(ua) && /Version/i.test(ua)) {608 uaData.browser.name = 'Safari';609 }610 }611 if (uaData.browser.name && !uaData.browser.version) {612 if (match = /Version\/([\w.]+)/i.exec(ua)) {613 uaData.browser.version = {614 original: match[1]615 };616 }617 }618 // if (uaData.os.name === 'Windows' && uaData.os.version) {619 // // Windows 8.1620 // if (uaData.os.version.alias === 'NT 6.3') {621 // uaData.os.version.alias = '8.1';622 // }623 // }624 // handle os625 if (uaData.os.name === 'Windows' || /Windows/i.test(ua)) {626 uaData.os.name = 'Windows';627 if (/NT 6.3/i.test(ua)) {628 uaData.os.version = {629 alias: '8.1',630 original: '8.1'631 };632 }633 else if (/NT 6.4/i.test(ua) || /NT 10.0/i.test(ua)) {634 uaData.os.version = {635 alias: '10',636 original: '10'637 };638 }639 }640 else if (uaData.os.name === 'Mac OS X') {641 uaData.os.name = 'Mac OS X';642 if (match = /Mac OS X[\s\_\-\/](\d+[\.\-\_]\d+[\.\-\_]?\d*)/i.exec(ua)) {643 uaData.os.version = {644 alias: match[1].replace(/_/g, '.'),645 original: match[1].replace(/_/g, '.')646 };647 }648 else {649 uaData.os.version = {650 alias: '',651 original: ''652 };653 }654 }655 else if (/Android/i.test(uaData.os.name)) {656 if (match = ua.match(/Android[\s\_\-\/i686]?[\s\_\-\/](\d+[\.\-\_]\d+[\.\-\_]?\d*)/i)) {657 uaData.os.version = {658 alias: match[1],659 original: match[1]660 };661 }662 }663 return uaData;...

Full Screen

Full Screen

wicg_uach.js

Source:wicg_uach.js Github

copy

Full Screen

1/*2 * Copyright 2008 The Closure Compiler Authors3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16/**17 * @fileoverview The current draft spec of User Agent Client Hint interface.18 * @see https://wicg.github.io/ua-client-hints/#interface19 * @externs20 */21/**22 * @see https://wicg.github.io/ua-client-hints/#dictdef-navigatoruabrandversion23 * @record24 * @struct25 */26function NavigatorUABrandVersion() {}27/** @type {string} */28NavigatorUABrandVersion.prototype.brand;29/** @type {string} */30NavigatorUABrandVersion.prototype.version;31/**32 * @see https://wicg.github.io/ua-client-hints/#dictdef-uadatavalues33 * @record34 * @struct35 */36function UADataValues() {}37/** @type {string} */38UADataValues.prototype.platform;39/** @type {string} */40UADataValues.prototype.platformVersion;41/** @type {string} */42UADataValues.prototype.architecture;43/** @type {string} */44UADataValues.prototype.model;45/** @type {string} */46UADataValues.prototype.uaFullVersion;47/** @type {string} */48UADataValues.prototype.bitness;49/** @type {boolean|undefined} */50UADataValues.prototype.wow64;51/** @type {!Array<!NavigatorUABrandVersion>|undefined} */52UADataValues.prototype.fullVersionList;53/**54 * @see https://wicg.github.io/ua-client-hints/#navigatoruadata55 * @record56 * @struct57 */58function NavigatorUAData() {}59/** @type {!Array<!NavigatorUABrandVersion>} */60NavigatorUAData.prototype.brands;61/** @type {boolean} */62NavigatorUAData.prototype.mobile;63/** @type {string} */64NavigatorUAData.prototype.platform;65/**66 * @param {!Array<string>} hints67 * @return {!Promise<!UADataValues>}68 */69NavigatorUAData.prototype.getHighEntropyValues = function(hints) {};70/**71 * @type {?NavigatorUAData}72 * @see https://wicg.github.io/ua-client-hints/#interface73 */74Navigator.prototype.userAgentData;75/**76 * @type {?NavigatorUAData}77 * @see https://wicg.github.io/ua-client-hints/#interface78 */...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = new WebPagetest('www.webpagetest.org');2wpt.getLocations(function(err, data) {3 if (err) return console.error(err);4 console.log(data);5});6var wpt = new WebPagetest('www.webpagetest.org');7wpt.getLocations(function(err, data) {8 if (err) return console.error(err);9 console.log(data);10});11var wpt = new WebPagetest('www.webpagetest.org');12wpt.getLocations(function(err, data) {13 if (err) return console.error(err);14 console.log(data);15});16var wpt = new WebPagetest('www.webpagetest.org');17wpt.getLocations(function(err, data) {18 if (err) return console.error(err);19 console.log(data);20});21var wpt = new WebPagetest('www.webpagetest.org');22wpt.getLocations(function(err, data) {23 if (err) return console.error(err);24 console.log(data);25});26var wpt = new WebPagetest('www.webpagetest.org');27wpt.getLocations(function(err, data) {28 if (err) return console.error(err);29 console.log(data);30});31var wpt = new WebPagetest('www.webpagetest.org');32wpt.getLocations(function(err, data) {33 if (err) return console.error(err);34 console.log(data);35});36var wpt = new WebPagetest('www.webpagetest.org');37wpt.getLocations(function(err, data) {38 if (err) return console.error(err);39 console.log(data);40});41var wpt = new WebPagetest('www.webpagetest.org');42wpt.getLocations(function(err, data) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api-wrapper');2var options = {3};4wpt.runTest(options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 wpt.uaData(data.data.testId, function(err, data) {10 if (err) {11 console.log(err);12 } else {13 console.log(data);14 }15 });16 }17});18var wpt = require('wpt-api-wrapper');19var options = {20};21wpt.runTest(options, function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wpt = require('wpt-api-wrapper');29wpt.getLocations(function(err, data) {30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36var wpt = require('wpt-api-wrapper');37wpt.getBrowsers(function(err, data) {38 if (err) {39 console.log(err);40 } else {41 console.log(data);42 }43});44var wpt = require('wpt-api-wrapper');45wpt.getConnectivity(function(err, data) {46 if (err) {47 console.log(err);48 } else {49 console.log(data);50 }51});52var wpt = require('wpt-api-wrapper');53wpt.getTesters(function(err, data) {54 if (err) {55 console.log(err);56 } else {57 console.log(data);58 }59});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wptClient = wpt('your wpt API key');3wptClient.uaData(function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(data);8 }9});10var wpt = require('wpt');11var wptClient = wpt('your wpt API key');12var testOptions = {13};14wptClient.runTest(testOptions, function(err, data) {15 if (err) {16 console.log('Error: ' + err);17 } else {18 console.log(data);19 }20});21var wpt = require('wpt');22var wptClient = wpt('your wpt API key');23var testId = '160907_8F_1Y';24wptClient.getTestResults(testId, function(err, data) {25 if (err) {26 console.log('Error: ' + err);27 } else {28 console.log(data);29 }30});31var wpt = require('wpt');32var wptClient = wpt('your wpt API key');33var testId = '160907_8F_1Y';34wptClient.getTestStatus(testId, function(err, data) {35 if (err) {36 console.log('Error: ' + err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42var wptClient = wpt('your wpt API key');43var testId = '160907_8F_1Y';44wptClient.getTestResults(testId, function(err, data) {45 if (err) {46 console.log('Error: ' + err);47 } else {48 console.log(data);49 }50});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wptData = wpt.uaData('chrome', 'win10');3console.log(wptData);4{ browser: 'chrome',5 device: 'desktop' }6wpt.getLocations()7{ locations:

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = new WebPageTest('www.webpagetest.org');2wpt.runTest(url, function(err, data) {3 if (err) {4 console.log(err);5 } else {6 wpt.getTestResults(data.data.testId, function(err, data) {7 if (err) {8 console.log(err);9 } else {10 console.log(data.data.testId);11 console.log(data.data.userUrl);12 console.log(data.data.summary);13 console.log(data.data.median.firstView.userAgent);14 console.log(data.data.median.firstView.uaData);15 }16 });17 }18});19var wpt = new WebPageTest('www.webpagetest.org');20wpt.runTest(url, function(err, data) {21 if (err) {22 console.log(err);23 } else {24 wpt.getTestResults(data.data.testId, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data.data.testId);29 console.log(data.data.userUrl);30 console.log(data.data

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getTestResults('160731_7T_1a8b0c9b9d3c6a7d6f8b6c0b6d0b6e1c', function(err, data) {4 console.log(data.data.median.firstView.uaFamily);5 console.log(data.data.median.firstView.uaName);6 console.log(data.data.median.firstView.uaVersion);7 console.log(data.data.median.firstView.uaEngine);8 console.log(data.data.median.firstView.uaEngineVersion);9 console.log(data.data.median.firstView.uaArchitecture);10 console.log(data.data.median.firstView.uaPlatform);11 console.log(data.data.median.firstView.uaPlatformVersion);12 console.log(data.data.median.firstView.uaDevice);13 console.log(data.data.median.firstView.uaDeviceType);14 console.log(data.data.median.firstView.uaDeviceVendor);15});16var wpt = require('webpagetest');17var wpt = new WebPageTest('www.webpagetest.org');18wpt.getTestResults('160731_7T_1a8b0c9b9d3c6a7d6f8b6c0b6d0b6e1c', function(err, data) {19 console.log(data.data.median.firstView.customMetrics);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23wpt.getTestResults('160731_7T_1a8b0c9b9d3c6a7d6f8b6c0b6d0b6e1c', function(err, data) {24 console.log(data.data.median.firstView.customMetrics);25});26var wpt = require('webpagetest');27var wpt = new WebPageTest('www.webpagetest.org');28wpt.getTestResults('160731_7T_1a8b0c9b9d3c6a7d6f8b6c0b6d0b6e1c', function(err, data) {29 console.log(data.data

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful