Skip to content

Commit

Permalink
feat: Add chinaOutFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
proletarius101 committed Aug 6, 2020
1 parent f25ac35 commit b026b0d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/guide/custom-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ Surgio 内置多个节点名国别/地区过滤器。除非是火星文,Surgio
- singaporeFilter
- koreaFilter
- taiwanFilter
- chinaBackFilter(回国节点过滤)
- chinaBackFilter(得到回国节点)
- chinaOutFilter(得到出国节点)

### 协议过滤器

Expand Down
3 changes: 3 additions & 0 deletions lib/generator/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
taiwanFilter,
usFilter,
chinaBackFilter,
chinaOutFilter,
validateFilter,
youtubePremiumFilter as defaultYoutubePremiumFilter,
shadowsocksFilter,
Expand Down Expand Up @@ -160,6 +161,7 @@ export class Artifact extends EventEmitter {
singaporeFilter,
taiwanFilter,
chinaBackFilter,
chinaOutFilter,
shadowsocksFilter,
shadowsocksrFilter,
vmessFilter,
Expand Down Expand Up @@ -189,6 +191,7 @@ export class Artifact extends EventEmitter {
singaporeFilter,
taiwanFilter,
chinaBackFilter,
chinaOutFilter,
netflixFilter,
youtubePremiumFilter,
...customFilters,
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ export const chinaBackFilter: NodeNameFilterType = item => {
].some(key => item.nodeName.includes(key));
};

export const chinaOutFilter: NodeNameFilterType = item => {
return !chinaBackFilter(item);
}

export const youtubePremiumFilter: NodeNameFilterType = mergeFilters([usFilter, japanFilter, koreaFilter, hkFilter, singaporeFilter]);

// istanbul ignore next
Expand Down
15 changes: 15 additions & 0 deletions test/utils/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ test('chinaBackFilter', t => {
}));
});

test('chinaOutFilter', t => {
t.false(filter.chinaOutFilter({
nodeName: '回国',
type: NodeTypeEnum.Shadowsocks,
}));
t.false(filter.chinaOutFilter({
nodeName: '中国上海',
type: NodeTypeEnum.Shadowsocks,
}));
t.true(filter.chinaOutFilter({
nodeName: 'US 1',
type: NodeTypeEnum.Shadowsocks,
}));
});

test('useSortedKeywords', t => {
const fn = filter.useSortedKeywords(['test', '测试']);
const result = fn.filter([
Expand Down

0 comments on commit b026b0d

Please sign in to comment.