mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 07:58:45 +03:00
Re-use previous result instead of re-parse it all over again
This commit is contained in:
parent
5d2acd8fe7
commit
4711805a1c
@ -847,9 +847,13 @@
|
|||||||
}
|
}
|
||||||
UAParserData.prototype.withClientHints = function () {
|
UAParserData.prototype.withClientHints = function () {
|
||||||
|
|
||||||
|
var prevData = this;
|
||||||
|
|
||||||
// nodejs / non-client-hints browsers
|
// nodejs / non-client-hints browsers
|
||||||
if (!NAVIGATOR_UADATA) {
|
if (!NAVIGATOR_UADATA) {
|
||||||
return new UAParserItem(itemType, ua, rgxMap, uaCH).parseCH().get();
|
var item = new UAParserItem(itemType, ua, rgxMap, uaCH);
|
||||||
|
item.data = prevData;
|
||||||
|
return item.parseCH().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// browsers based on chromium 85+
|
// browsers based on chromium 85+
|
||||||
@ -857,7 +861,9 @@
|
|||||||
.getHighEntropyValues(CH_ALL_VALUES)
|
.getHighEntropyValues(CH_ALL_VALUES)
|
||||||
.then(function (res) {
|
.then(function (res) {
|
||||||
var JS_UACH = new UAParserDataCH(res, false);
|
var JS_UACH = new UAParserDataCH(res, false);
|
||||||
return new UAParserItem(itemType, ua, rgxMap, JS_UACH).parseCH().get();
|
var item = new UAParserItem(itemType, ua, rgxMap, JS_UACH);
|
||||||
|
item.data = prevData;
|
||||||
|
return item.parseCH().get();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -944,8 +950,29 @@
|
|||||||
['rgxMap', rgxMap],
|
['rgxMap', rgxMap],
|
||||||
['data', createUAParserData(itemType, ua, rgxMap, uaCH)]
|
['data', createUAParserData(itemType, ua, rgxMap, uaCH)]
|
||||||
]);
|
]);
|
||||||
this.parse();
|
if(this.itemType == UA_RESULT) {
|
||||||
var isSelfNav = NAVIGATOR && NAVIGATOR.userAgent == ua;
|
var createUAParserItem = function (itemType) {
|
||||||
|
return new UAParserItem(itemType, ua, rgxMap[itemType], uaCH).parseUA().get();
|
||||||
|
};
|
||||||
|
this.set('ua', ua)
|
||||||
|
.set(UA_BROWSER, createUAParserItem(UA_BROWSER))
|
||||||
|
.set(UA_CPU, createUAParserItem(UA_CPU))
|
||||||
|
.set(UA_DEVICE, createUAParserItem(UA_DEVICE))
|
||||||
|
.set(UA_ENGINE, createUAParserItem(UA_ENGINE))
|
||||||
|
.set(UA_OS, createUAParserItem(UA_OS))
|
||||||
|
.get();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
UAParserItem.prototype.get = function (prop) {
|
||||||
|
if (!prop) return this.data;
|
||||||
|
return this.data.hasOwnProperty(prop) ? this.data[prop] : undefined;
|
||||||
|
};
|
||||||
|
UAParserItem.prototype.parseUA = function () {
|
||||||
|
if (this.itemType != UA_RESULT) {
|
||||||
|
rgxMapper.call(this.data, this.ua, this.rgxMap);
|
||||||
|
}
|
||||||
|
var isSelfNav = NAVIGATOR && NAVIGATOR.userAgent == this.ua;
|
||||||
switch(this.itemType) {
|
switch(this.itemType) {
|
||||||
case UA_BROWSER:
|
case UA_BROWSER:
|
||||||
// Brave-specific detection
|
// Brave-specific detection
|
||||||
@ -968,28 +995,6 @@
|
|||||||
if (isSelfNav && !this.get(NAME) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[PLATFORM]) {
|
if (isSelfNav && !this.get(NAME) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[PLATFORM]) {
|
||||||
this.set(NAME, NAVIGATOR_UADATA[PLATFORM]);
|
this.set(NAME, NAVIGATOR_UADATA[PLATFORM]);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case UA_RESULT:
|
|
||||||
var createUAParserItem = function (itemType) {
|
|
||||||
return new UAParserItem(itemType, ua, rgxMap[itemType], uaCH).get();
|
|
||||||
};
|
|
||||||
this.set('ua', ua)
|
|
||||||
.set(UA_BROWSER, createUAParserItem(UA_BROWSER))
|
|
||||||
.set(UA_CPU, createUAParserItem(UA_CPU))
|
|
||||||
.set(UA_DEVICE, createUAParserItem(UA_DEVICE))
|
|
||||||
.set(UA_ENGINE, createUAParserItem(UA_ENGINE))
|
|
||||||
.set(UA_OS, createUAParserItem(UA_OS))
|
|
||||||
.get();
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
UAParserItem.prototype.get = function (prop) {
|
|
||||||
if (!prop) return this.data;
|
|
||||||
return this.data.hasOwnProperty(prop) ? this.data[prop] : undefined;
|
|
||||||
};
|
|
||||||
UAParserItem.prototype.parse = function () {
|
|
||||||
if (this.itemType != UA_RESULT) {
|
|
||||||
rgxMapper.call(this.data, this.ua, this.rgxMap);
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@ -1038,8 +1043,11 @@
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UA_RESULT:
|
case UA_RESULT:
|
||||||
|
var prevData = this.data;
|
||||||
var createUAParserItemWithCH = function (itemType) {
|
var createUAParserItemWithCH = function (itemType) {
|
||||||
return new UAParserItem(itemType, ua, rgxMap[itemType], uaCH).parseCH().get();
|
var item = new UAParserItem(itemType, ua, rgxMap[itemType], uaCH);
|
||||||
|
item.data = prevData[itemType];
|
||||||
|
return item.parseCH().get();
|
||||||
};
|
};
|
||||||
this.set('ua', ua)
|
this.set('ua', ua)
|
||||||
.set(UA_BROWSER, createUAParserItemWithCH(UA_BROWSER))
|
.set(UA_BROWSER, createUAParserItemWithCH(UA_BROWSER))
|
||||||
@ -1092,7 +1100,7 @@
|
|||||||
|
|
||||||
createUAParserItemFunc = function (itemType) {
|
createUAParserItemFunc = function (itemType) {
|
||||||
return function () {
|
return function () {
|
||||||
return new UAParserItem(itemType, userAgent, itemType == UA_RESULT ? regexMap : regexMap[itemType], HTTP_UACH).get();
|
return new UAParserItem(itemType, userAgent, itemType == UA_RESULT ? regexMap : regexMap[itemType], HTTP_UACH).parseUA().get();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user