@@ -262,8 +262,12 @@ let fheaddMethod = '%APPEND%'
262262let skipaddMethod = '%APPEND%'
263263let realaddMethod = '%APPEND%'
264264
265+ let hn2 = false //surge模块中带有禁用MITM参数时无法捕捉hostname,此变量用以判断有无此类参数,以便后续解析
266+ let hn2name = 'hostname'
267+
265268//待输出
266269let modInfo = [ ] //模块简介
270+ let loonArg = [ ] //[Argument]
267271let httpFrame = '' //Stash的http:父框架
268272let tiles = [ ] //磁贴覆写
269273let General = [ ]
@@ -513,18 +517,20 @@ if (binaryInfo != null && binaryInfo.length > 0) {
513517 if ( / ^ # ! .+ ?= \s * $ / . test ( x ) ) {
514518 } else if ( isLooniOS && / ^ # ! (?: s e l e c t | i n p u t ) \s * = \s * .+ / . test ( x ) ) {
515519 getInputInfo ( x , modInputBox )
516- } else if ( / ^ # ! .+ ?= .+ / . test ( x ) && ! / ^ # ! (?: s e l e c t | i n p u t ) \s * = \s * .+ / . test ( x ) ) {
520+ } else if ( / ^ # ! .+ ?= .+ / . test ( x ) && ! / ^ # ! (?: s e l e c t | i n p u t | a r g u m e n t s ) \s * = \s * .+ / . test ( x ) ) {
517521 getModInfo ( x )
518522 }
519523
520524 //#!arguments参数
521- if ( ! isSurgeiOS && / ^ # ! a r g u m e n t s \s * = \s * .+ / . test ( x ) ) {
525+ if ( / ^ # ! a r g u m e n t s \s * = \s * .+ / . test ( x ) || / ^ [ ^ # ] = \s * ( i n p u t | s e l e c t | s w i t c h ) \s * , / . test ( x ) ) {
522526 parseArguments ( x )
523527 }
524528
525529 //hostname
526530 if ( / ^ h o s t n a m e \s * = .+ / . test ( x ) ) hnaddMethod = getHn ( x , hnBox , hnaddMethod )
527531
532+ if ( hn2 == true && x . match ( hn2name ) ) hnaddMethod = getHn ( x , hnBox , hnaddMethod )
533+
528534 if ( / ^ f o r c e - h t t p - e n g i n e - h o s t s \s * = .+ / . test ( x ) ) fheaddMethod = getHn ( x , fheBox , fheaddMethod )
529535
530536 if ( / ^ s k i p - p r o x y \s * = .+ / . test ( x ) ) skipaddMethod = getHn ( x , skipBox , skipaddMethod )
@@ -805,6 +811,8 @@ if (binaryInfo != null && binaryInfo.length > 0) {
805811 ? getJsInfo ( x , / [ = , \s ] \s * c r o n e x p r ? \s * = \s * / )
806812 : / c r o n \s + " / . test ( x )
807813 ? x . split ( '"' ) [ 1 ]
814+ : / c r o n \s + [ ^ \s ] + ?\s + /
815+ ? x . split ( / \s / ) [ 1 ]
808816 : ''
809817 ability = getJsInfo ( x , / [ = , \s ] \s * a b i l i t y \s * = \s * / )
810818 engine = getJsInfo ( x , / [ = , \s ] \s * e n g i n e \s * = \s * / )
@@ -1046,6 +1054,17 @@ if (binaryInfo != null && binaryInfo.length > 0) {
10461054 realBox = pieceHn ( realBox )
10471055 if ( synMitm ) fheBox = hnBox
10481056
1057+ if ( isSurgeiOS && sgArg . length > 0 ) {
1058+ let sgargArr = [ ]
1059+ for ( let i = 0 ; i < sgArg . length ; i ++ ) {
1060+ let key = sgArg [ i ] . key
1061+ let value = sgArg [ i ] . value . split ( ',' ) [ 0 ] . trim ( )
1062+ let a = key + ':' + value
1063+ sgargArr . push ( a )
1064+ }
1065+ modInfoObj [ 'arguments' ] = ( sgargArr [ 0 ] || '' ) && `${ sgargArr . join ( ',' ) } `
1066+ }
1067+
10491068 //模块信息输出
10501069 switch ( targetApp ) {
10511070 case 'surge-module' :
@@ -1085,6 +1104,18 @@ if (binaryInfo != null && binaryInfo.length > 0) {
10851104 break
10861105 } //模块信息输出结束
10871106
1107+ //[Argument]输出
1108+ if ( isLooniOS && sgArg . length > 0 ) {
1109+ for ( let i = 0 ; i < sgArg . length ; i ++ ) {
1110+ let key = sgArg [ i ] . key
1111+ let type = sgArg [ i ] . type
1112+ let value = sgArg [ i ] . value
1113+ if ( type == 'switch' ) value = / ^ t r u e / . test ( value ) ? 'true,false' : 'false,true'
1114+ let tag = sgArg [ i ] . tag
1115+ loonArg . push ( key + '=' + type + ',' + value + ',' + tag )
1116+ }
1117+ }
1118+
10881119 //rule输出 switch不适合
10891120 for ( let i = 0 ; i < ruleBox . length ; i ++ ) {
10901121 noteK = ruleBox [ i ] . noteK ? '#' : ''
@@ -1403,6 +1434,8 @@ if (binaryInfo != null && binaryInfo.length > 0) {
14031434
14041435 cronexp = reJsValue ( nCron || 'null' , ncronexp , jsname , ori , cronexp )
14051436
1437+ cronexp = / , / . test ( cronexp ) ? '"' + cronexp + '"' : cronexp
1438+
14061439 jsname = reJsValue ( njsnametarget || 'null' , njsname , jsname , ori , jsname )
14071440
14081441 timeout = reJsValue ( timeoutt || 'null' , timeoutv , jsname , ori , timeout )
@@ -1485,9 +1518,8 @@ if (binaryInfo != null && binaryInfo.length > 0) {
14851518 jsname +
14861519 ' = type=' +
14871520 jstype +
1488- ', cronexp=" ' +
1521+ ', cronexp=' +
14891522 cronexp +
1490- '"' +
14911523 ', script-path=' +
14921524 jsurl +
14931525 updatetime +
@@ -1501,9 +1533,8 @@ if (binaryInfo != null && binaryInfo.length > 0) {
15011533 mark +
15021534 noteK +
15031535 jstype +
1504- ' " ' +
1536+ ' ' +
15051537 cronexp +
1506- '"' +
15071538 ' script-path=' +
15081539 jsurl +
15091540 timeout +
@@ -1628,7 +1659,7 @@ if (binaryInfo != null && binaryInfo.length > 0) {
16281659 providers . push ( `${ noteK2 } "` + jsname + '":' + `${ noteKn4 } url: ` + jsurl + `${ noteKn4 } interval: 86400` )
16291660 }
16301661 if ( jstype == 'cron' ) {
1631- cron . push ( mark + `${ noteK4 } - name: "` + jsname + `"${ noteKn6 } cron: " ` + cronexp + `" ${ timeout } ` + jsarg )
1662+ cron . push ( mark + `${ noteK4 } - name: "` + jsname + `"${ noteKn6 } cron: ` + cronexp + `${ timeout } ` + jsarg )
16321663 providers . push ( `${ noteK2 } "` + jsname + '":' + `${ noteKn4 } url: ` + jsurl + `${ noteKn4 } interval: 86400` )
16331664 }
16341665 if ( jstype == 'generic' ) {
@@ -1653,6 +1684,8 @@ if (binaryInfo != null && binaryInfo.length > 0) {
16531684 case 'loon-plugin' :
16541685 modInfo = ( modInfo [ 0 ] || '' ) && `${ modInfo . join ( '\n' ) } `
16551686
1687+ loonArg = ( loonArg [ 0 ] || '' ) && `[Argument]\n${ loonArg . join ( '\n' ) } `
1688+
16561689 rules = ( rules [ 0 ] || '' ) && `[Rule]\n${ rules . join ( '\n' ) } `
16571690
16581691 Panel = ( Panel [ 0 ] || '' ) && `[Panel]\n${ Panel . join ( '\n\n' ) } `
@@ -1670,15 +1703,19 @@ if (binaryInfo != null && binaryInfo.length > 0) {
16701703 script = ( script [ 0 ] || '' ) && `[Script]\n${ script . join ( '\n\n' ) } `
16711704
16721705 if ( isLooniOS ) {
1673- MITM = hnBox . length > 0 ? ' [MITM]\nhostname = ' + hnBox : ''
1706+ MITM = hnBox . length > 0 ? ` [MITM]\n ${ hn2name } = ` + hnBox : ''
16741707 fheBox . length > 0 && General . push ( 'force-http-engine-hosts = ' + fheBox )
16751708 skipBox . length > 0 && General . push ( 'skip-proxy = ' + skipBox )
16761709 realBox . length > 0 && General . push ( 'real-ip = ' + realBox )
16771710 General = ( General [ 0 ] || '' ) && `[General]\n${ General . join ( '\n\n' ) } `
16781711 }
16791712
16801713 if ( isSurgeiOS || isShadowrocket ) {
1681- MITM = hnBox . length > 0 ? `[MITM]\nhostname = ${ hnaddMethod } ` + hnBox : ''
1714+ if ( isSurgeiOS ) {
1715+ MITM = hnBox . length > 0 ? `[MITM]\n${ hn2name } = ${ hnaddMethod } ` + hnBox : ''
1716+ } else {
1717+ MITM = hnBox . length > 0 ? `[MITM]\nhostname = ${ hnaddMethod } ` + hnBox : ''
1718+ }
16821719 fheBox . length > 0 && General . push ( `force-http-engine-hosts = ${ fheaddMethod } ` + fheBox )
16831720 skipBox . length > 0 && General . push ( `skip-proxy = ${ skipaddMethod } ` + skipBox )
16841721 realBox . length > 0 && General . push ( `always-real-ip = ${ realaddMethod } ` + realBox )
@@ -1687,6 +1724,8 @@ if (binaryInfo != null && binaryInfo.length > 0) {
16871724
16881725 body = `${ modInfo }
16891726
1727+ ${ loonArg }
1728+
16901729${ General }
16911730
16921731${ rules }
@@ -1788,12 +1827,22 @@ ${providers}
17881827 break
17891828 } //输出内容结束
17901829 body = body . replace ( / \n { 2 , } / g, '\n\n' )
1791- if ( sgArg . length > 0 ) {
1830+ if ( ! isSurgeiOS && ! isLooniOS && sgArg . length > 0 ) {
1831+ body = body . replaceAll ( '{{{' , '{' ) . replaceAll ( '}}}' , '}' )
1832+ for ( let i = 0 ; i < sgArg . length ; i ++ ) {
1833+ let e = '{' + sgArg [ i ] . key + '}'
1834+ let r = sgArg [ i ] . value . split ( ',' ) [ 0 ]
1835+ body = body . replaceAll ( e , r )
1836+ } //for
1837+ } else if ( isSurgeiOS ) {
1838+ body = body . replaceAll ( '{{{' , '{' ) . replaceAll ( '}}}' , '}' )
17921839 for ( let i = 0 ; i < sgArg . length ; i ++ ) {
1793- let e = '{{{ ' + sgArg [ i ] . key + '}} }'
1794- let r = sgArg [ i ] . value
1840+ let e = '{' + sgArg [ i ] . key + '}'
1841+ let r = '{{{' + sgArg [ i ] . key + '}}}'
17951842 body = body . replaceAll ( e , r )
17961843 } //for
1844+ } else if ( isLooniOS ) {
1845+ body = body . replaceAll ( '{{{' , '{' ) . replaceAll ( '}}}' , '}' )
17971846 }
17981847
17991848 eval ( evJsmodi )
@@ -2264,14 +2313,37 @@ function getPolicy(str) {
22642313}
22652314
22662315function parseArguments ( str ) {
2267- const queryString = str . split ( / # ! a r g u m e n t s \s * = \s * / ) [ 1 ] //获取查询字符串部分
2268- const regex = / ( [ ^ : , ] + ) : ( \s * " .+ ?" | [ ^ , ] * ) / g //匹配键值对的正则表达式
2269- let match
2316+ if ( / # ! a r g u m e n t s / . test ( str ) ) {
2317+ const queryString = str . split ( / # ! a r g u m e n t s \s * = \s * / ) [ 1 ] //获取查询字符串部分
2318+ const regex = / ( [ ^ : , ] + ) : ( \s * " .+ ?" | [ ^ , ] * ) / g //匹配键值对的正则表达式
2319+ let match
2320+
2321+ while ( ( match = regex . exec ( queryString ) ) ) {
2322+ const key = match [ 1 ] . trim ( ) . replace ( / ^ " ( .+ ) " $ / , '$1' ) //去除头尾空白符和引号
2323+ const value = match [ 2 ] . trim ( ) . replace ( / ^ " ( .+ ) " $ / , '$1' ) //去除头尾空白符和引号
2324+ const type = / ^ ( t r u e | f a l s e ) $ / . test ( value ) ? 'switch' : 'input'
2325+ const tag = `tag=${ key } , desc=${ key } `
2326+
2327+ sgArg . push ( { key, value, type, tag } ) //将键值对添加到对象中
2328+
2329+ if ( value == 'hostname' ) {
2330+ hn2 = true
2331+ hn2name = '{{{' + key + '}}}'
2332+ }
2333+ }
2334+ } else {
2335+ const regex = / ( ^ .* ?) \s * = \s * ( .* ?) \s * , ( .* ?) , \s * ( [ ^ , ] * \s * = .+ ) / //获取信息
2336+ const key = str . match ( regex ) [ 1 ]
2337+ const type = str . match ( regex ) [ 2 ]
2338+ const value = str . match ( regex ) [ 3 ]
2339+ const tag = str . match ( regex ) [ 4 ]
22702340
2271- while ( ( match = regex . exec ( queryString ) ) ) {
2272- const key = match [ 1 ] . trim ( ) . replace ( / ^ " ( .+ ) " $ / , '$1' ) //去除头尾空白符和引号
2273- const value = match [ 2 ] . trim ( ) . replace ( / ^ " ( .+ ) " $ / , '$1' ) //去除头尾空白符和引号
2274- sgArg . push ( { key, value } ) //将键值对添加到对象中
2341+ sgArg . push ( { key, value, type, tag } )
2342+
2343+ if ( value == 'hostname' ) {
2344+ hn2 = true
2345+ hn2name = '{{{' + key + '}}}'
2346+ }
22752347 }
22762348}
22772349
0 commit comments