diff --git a/src/apps/config.ts b/src/apps/config.ts index d939c742..3597687a 100644 --- a/src/apps/config.ts +++ b/src/apps/config.ts @@ -5,5 +5,6 @@ export const Server = process.env.NODE_ENV == 'production' ? 'https://sc.icodef. export const ExternalWhitelist = [ 'greasyfork.org', 'scriptcat.org', + 'tampermonkey.net.cn', 'openuserjs.org', ]; \ No newline at end of file diff --git a/src/pkg/match.ts b/src/pkg/match.ts index 1e5bdd7b..a62a733a 100644 --- a/src/pkg/match.ts +++ b/src/pkg/match.ts @@ -14,7 +14,7 @@ export class Match { }; } if (url == 'http*') { - return { scheme: '*', host: '*', path: '', search: '' }; + return { scheme: '*', host: '*', path: '*', search: '*' }; } match = /^(.*?)((\/.*?)(\?.*?|)|)$/.exec(url); if (match) { @@ -41,10 +41,10 @@ export class Match { u.scheme = 'http[s]'; break; } - u.host = u.host.replace(/\*/g, '.*?'); + u.host = u.host.replace(/\*/g, '[^/]*?'); // 处理 *.开头 - if (u.host.startsWith('.*?.')) { - u.host = '(.*?\.?)' + u.host.substr(4); + if (u.host.startsWith('[^/]*?.')) { + u.host = '([^/]*?\.?)' + u.host.substr(7); } // 处理顶域 if (u.host.endsWith('tld')) { diff --git a/tests/match.test.ts b/tests/match.test.ts index 6276dc12..6fb0a864 100644 --- a/tests/match.test.ts +++ b/tests/match.test.ts @@ -79,6 +79,28 @@ describe('UrlMatch2', () => { const url = new UrlMatch(); it('http*', () => { url.add('http*', 'ok1'); - expect(url.match('http://www.http*.com')).toEqual(['ok1']); + expect(url.match('http://www.http.com')).toEqual(['ok1']); + }); + it('port', () => { + url.add('http://domain:8080', 'ok2'); + expect(url.match('http://domain:8080/')).toEqual(['ok1', 'ok2']); + expect(url.match('http://domain:8080/123')).toEqual(['ok1']); + }); + it('无/', () => { + url.add('http://domain2', 'ok3'); + url.add('http://domain2*', 'ok4'); + expect(url.match('http://domain2/')).toEqual(['ok1', 'ok3', 'ok4']); + expect(url.match('http://domain2.com/')).toEqual(['ok1', 'ok4']); + expect(url.match('http://domain2/123')).toEqual(['ok1']); + }) +}); + +describe('UrlMatch3', () => { + const url = new UrlMatch(); + it('port', () => { + url.add('http://domain:*/', 'ok1'); + expect(url.match('http://domain:8080/')).toEqual(['ok1']); + expect(url.match('http://domain:8080')).toEqual(['ok1']); + expect(url.match('http://domain:8080/123')).toEqual([]); }); });