File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,19 +77,11 @@ $.ver = 'https://gitee.com/chavyleung/scripts/raw/master/box/release/box.release
7777 * http://boxjs.com/api/getdata => `/api/getdata`
7878 */
7979function getPath ( url ) {
80- // 如果以`/`结尾, 先去掉最后一个`/`
81- const fullpath = / \/ $ / . test ( url ) ? url . replace ( / \/ $ / , '' ) : url
82- const domain = getDomain ( url )
83- return new RegExp ( domain ) . test ( url ) ? fullpath . split ( domain ) [ 1 ] : undefined
84- }
85-
86- /**
87- * http://boxjs.com/ => `boxjs.com`
88- * http://127.0.0.1:9999/ => `127.0.0.1:9999`
89- */
90- function getDomain ( url ) {
91- const [ , domain ] = / h t t p s ? : \/ \/ ( .* ?) \/ .* / . exec ( url )
92- return domain
80+ // 如果以`/`结尾, 去掉最后一个`/`
81+ let end = url . lastIndexOf ( "/" ) === url . length - 1 ? - 1 : undefined
82+ // slice第二个参数传 undefined 会直接截到最后
83+ // indexOf第二个参数用来跳过前面的 "https://"
84+ return url . slice ( url . indexOf ( "/" , 8 ) , end )
9385}
9486
9587/**
Original file line number Diff line number Diff line change @@ -69,10 +69,11 @@ $.html = $.name
6969 * https://dns.google/api => `/api`
7070 */
7171function getPath ( url ) {
72- // 如果以`/`结尾, 先去掉最后一个`/`
73- const fullpath = / \/ $ / . test ( url ) ? url . replace ( / \/ $ / , '' ) : url
74- const [ , domain ] = / h t t p s ? : \/ \/ ( .* ?) \/ .* / . 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
7879function getSystemCfgs ( ) {
You can’t perform that action at this time.
0 commit comments