Skip to content

Commit 6947a76

Browse files
committed
Update getting from black list with and without www
1 parent 85411eb commit 6947a76

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/compositions/black-list.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { injecStorage } from "../storage/inject-storage";
22
import { StorageParams } from "../storage/storage-params";
3+
import { isDomainEquals } from "../utils/common";
4+
import { extractHostname } from "./extract-hostname";
35

46
export async function isInBlackList(url: string): Promise<boolean>{
57
const storage = injecStorage();
68
const blackList = await storage.getValue(StorageParams.BLACK_LIST) as string[];
7-
return blackList != undefined && blackList.indexOf(url) != -1 ? true : false;
9+
return blackList?.find(x => isDomainEquals(extractHostname(x), extractHostname(url))) !== undefined;
810
}

src/utils/common.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,20 @@ export function isEmpty(obj: any): boolean {
55
}
66

77
return JSON.stringify(obj) === JSON.stringify({});
8+
}
9+
10+
export function isDomainEquals(first:string, second:string) {
11+
if (first === second)
12+
return true;
13+
else {
14+
var resultUrl = function(url:string) {
15+
if (url.indexOf('www.') > -1)
16+
return url.split('www.')[1];
17+
return url;
18+
};
19+
20+
if (resultUrl(first) === resultUrl(second))
21+
return true;
22+
else return false;
23+
}
824
}

0 commit comments

Comments
 (0)