Skip to content

Commit 6e9a39e

Browse files
committed
更简洁的getPath()
1 parent a807d29 commit 6e9a39e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎chavy.box.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ $.html = $.name
6969
* https://dns.google/api => `/api`
7070
*/
7171
function getPath(url) {
72-
// 如果以`/`结尾, 先去掉最后一个`/`
73-
const fullpath = /\/$/.test(url) ? url.replace(/\/$/, '') : url
74-
const [, domain] = /https?:\/\/(.*?)\/.*/.exec($request.url)
75-
return new RegExp(domain).test(url) ? fullpath.split(domain)[1] : undefined
72+
// 如果以`/`结尾, 去掉最后一个`/`
73+
let end = url.lastIndexOf("/") === url.length - 1 ? -1 : undefined
74+
// slice第二个参数传 undefined 会直接截到最后
75+
// indexOf第二个参数用来跳过前面的 "https://"
76+
return url.slice(url.indexOf("/", 8), end)
7677
}
7778

7879
function getSystemCfgs() {

0 commit comments

Comments
 (0)