Skip to content

Commit

Permalink
又优化了下 UA 逻辑 现在两行就 ok 了
Browse files Browse the repository at this point in the history
  • Loading branch information
makeding committed Sep 11, 2020
1 parent 650afad commit e20e3c1
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions util/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,8 @@ function chooseUserAgent(ua = false) {
// Linux 就算了
]
}
let realUserAgentList = []
if (!ua)
realUserAgentList = (userAgentList.mobile).concat(userAgentList.pc) // concat 把两个 array 合并
else if (ua == 'mobile')
realUserAgentList = userAgentList.mobile
else if (ua == 'pc')
realUserAgentList = userAgentList.pc
else
return ua // 最后返回自定义的 ua
return realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)]
let realUserAgentList = userAgentList[ua] || (userAgentList.mobile).concat(userAgentList.pc)
return (['mobile', 'pc', false].indexOf(ua) > -1) ? realUserAgentList[Math.floor(Math.random() * realUserAgentList.length)] : ua
}
const createRequest = (method, url, data, options) => {
return new Promise((resolve, reject) => {
Expand Down

0 comments on commit e20e3c1

Please sign in to comment.