add chromeOS
This commit is contained in:
@@ -37,6 +37,7 @@ const (
|
|||||||
MacOS = "macOS"
|
MacOS = "macOS"
|
||||||
IOS = "iOS"
|
IOS = "iOS"
|
||||||
Linux = "Linux"
|
Linux = "Linux"
|
||||||
|
ChromeOS = "CrOS"
|
||||||
|
|
||||||
Opera = "Opera"
|
Opera = "Opera"
|
||||||
OperaMini = "Opera Mini"
|
OperaMini = "Opera Mini"
|
||||||
@@ -115,6 +116,11 @@ func Parse(userAgent string) UserAgent {
|
|||||||
ua.OSVersion = tokens[Linux]
|
ua.OSVersion = tokens[Linux]
|
||||||
ua.Desktop = true
|
ua.Desktop = true
|
||||||
|
|
||||||
|
case tokens.exists("CrOS"):
|
||||||
|
ua.OS = ChromeOS
|
||||||
|
ua.OSVersion = tokens[ChromeOS]
|
||||||
|
ua.Desktop = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for s, val := range sys {
|
// for s, val := range sys {
|
||||||
@@ -359,6 +365,9 @@ func checkVer(s string) (name, v string) {
|
|||||||
switch s[:i] {
|
switch s[:i] {
|
||||||
case "Linux", "Windows NT", "Windows Phone OS", "MSIE", "Android":
|
case "Linux", "Windows NT", "Windows Phone OS", "MSIE", "Android":
|
||||||
return s[:i], s[i+1:]
|
return s[:i], s[i+1:]
|
||||||
|
case "CrOS x86_64", "CrOS aarch64" :
|
||||||
|
j := strings.LastIndex(s[:i]," ")
|
||||||
|
return s[:j],s[j+1:i]
|
||||||
default:
|
default:
|
||||||
return s, ""
|
return s, ""
|
||||||
}
|
}
|
||||||
@@ -414,7 +423,7 @@ func (p properties) findBestMatch(withVerOnly bool) string {
|
|||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
for k, v := range p {
|
for k, v := range p {
|
||||||
switch k {
|
switch k {
|
||||||
case Chrome, Firefox, Safari, "Version", "Mobile", "Mobile Safari", "Mozilla", "AppleWebKit", "Windows NT", "Windows Phone OS", Android, "Macintosh", Linux, "GSA":
|
case Chrome, Firefox, Safari, "Version", "Mobile", "Mobile Safari", "Mozilla", "AppleWebKit", "Windows NT", "Windows Phone OS", Android, "Macintosh", Linux, "GSA", ChromeOS:
|
||||||
default:
|
default:
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if v != "" { // in first check, only return keys with value
|
if v != "" { // in first check, only return keys with value
|
||||||
@@ -432,7 +441,6 @@ func (p properties) findBestMatch(withVerOnly bool) string {
|
|||||||
var rxMacOSVer = regexp.MustCompile("[_\\d\\.]+")
|
var rxMacOSVer = regexp.MustCompile("[_\\d\\.]+")
|
||||||
|
|
||||||
func findVersion(s string) string {
|
func findVersion(s string) string {
|
||||||
|
|
||||||
if ver := rxMacOSVer.FindString(s); ver != "" {
|
if ver := rxMacOSVer.FindString(s); ver != "" {
|
||||||
return strings.Replace(ver, "_", ".", -1)
|
return strings.Replace(ver, "_", ".", -1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ func TestParse(t *testing.T) {
|
|||||||
{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36", ua.Chrome, "87.0.4280.141", "desktop", ua.MacOS},
|
{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36", ua.Chrome, "87.0.4280.141", "desktop", ua.MacOS},
|
||||||
|
|
||||||
// other
|
// other
|
||||||
|
{"Mozilla/5.0 (X11; CrOS x86_64 14150.74.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.114 Safari/537.36",ua.Chrome, "94.0.4606.114", "desktop", ua.ChromeOS},
|
||||||
{"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 Google (+https://developers.google.com/+/web/snippet/)", ua.Chrome, "56.0.2924.87", "bot", ua.Linux}, // Google+ fetch
|
{"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 Google (+https://developers.google.com/+/web/snippet/)", ua.Chrome, "56.0.2924.87", "bot", ua.Linux}, // Google+ fetch
|
||||||
|
|
||||||
// tools
|
// tools
|
||||||
|
|||||||
Reference in New Issue
Block a user