File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ export const Server = process.env.NODE_ENV == 'production' ? 'https://sc.icodef.
55export const ExternalWhitelist = [
66 'greasyfork.org' ,
77 'scriptcat.org' ,
8+ 'tampermonkey.net.cn' ,
89 'openuserjs.org' ,
910] ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export class Match<T> {
1414 } ;
1515 }
1616 if ( url == 'http*' ) {
17- return { scheme : '*' , host : '*' , path : '' , search : '' } ;
17+ return { scheme : '*' , host : '*' , path : '* ' , search : '* ' } ;
1818 }
1919 match = / ^ ( .* ?) ( ( \/ .* ?) ( \? .* ?| ) | ) $ / . exec ( url ) ;
2020 if ( match ) {
@@ -41,10 +41,10 @@ export class Match<T> {
4141 u . scheme = 'http[s]' ;
4242 break ;
4343 }
44- u . host = u . host . replace ( / \* / g, '. *?' ) ;
44+ u . host = u . host . replace ( / \* / g, '[^/] *?' ) ;
4545 // 处理 *.开头
46- if ( u . host . startsWith ( '. *?.' ) ) {
47- u . host = '(. *?\.?)' + u . host . substr ( 4 ) ;
46+ if ( u . host . startsWith ( '[^/] *?.' ) ) {
47+ u . host = '([^/] *?\.?)' + u . host . substr ( 7 ) ;
4848 }
4949 // 处理顶域
5050 if ( u . host . endsWith ( 'tld' ) ) {
Original file line number Diff line number Diff line change @@ -79,6 +79,28 @@ describe('UrlMatch2', () => {
7979 const url = new UrlMatch < string > ( ) ;
8080 it ( 'http*' , ( ) => {
8181 url . add ( 'http*' , 'ok1' ) ;
82- expect ( url . match ( 'http://www.http*.com' ) ) . toEqual ( [ 'ok1' ] ) ;
82+ expect ( url . match ( 'http://www.http.com' ) ) . toEqual ( [ 'ok1' ] ) ;
83+ } ) ;
84+ it ( 'port' , ( ) => {
85+ url . add ( 'http://domain:8080' , 'ok2' ) ;
86+ expect ( url . match ( 'http://domain:8080/' ) ) . toEqual ( [ 'ok1' , 'ok2' ] ) ;
87+ expect ( url . match ( 'http://domain:8080/123' ) ) . toEqual ( [ 'ok1' ] ) ;
88+ } ) ;
89+ it ( '无/' , ( ) => {
90+ url . add ( 'http://domain2' , 'ok3' ) ;
91+ url . add ( 'http://domain2*' , 'ok4' ) ;
92+ expect ( url . match ( 'http://domain2/' ) ) . toEqual ( [ 'ok1' , 'ok3' , 'ok4' ] ) ;
93+ expect ( url . match ( 'http://domain2.com/' ) ) . toEqual ( [ 'ok1' , 'ok4' ] ) ;
94+ expect ( url . match ( 'http://domain2/123' ) ) . toEqual ( [ 'ok1' ] ) ;
95+ } )
96+ } ) ;
97+
98+ describe ( 'UrlMatch3' , ( ) => {
99+ const url = new UrlMatch < string > ( ) ;
100+ it ( 'port' , ( ) => {
101+ url . add ( 'http://domain:*/' , 'ok1' ) ;
102+ expect ( url . match ( 'http://domain:8080/' ) ) . toEqual ( [ 'ok1' ] ) ;
103+ expect ( url . match ( 'http://domain:8080' ) ) . toEqual ( [ 'ok1' ] ) ;
104+ expect ( url . match ( 'http://domain:8080/123' ) ) . toEqual ( [ ] ) ;
83105 } ) ;
84106} ) ;
You can’t perform that action at this time.
0 commit comments