Additional addresses (#126)

This commit is contained in:
Jaco Greeff
2021-02-19 09:03:17 +01:00
committed by GitHub
parent 41cd5da2b3
commit 5c6e6421a7
3 changed files with 25 additions and 3 deletions
+1
View File
@@ -25,3 +25,4 @@ package-lock.json
report.*.json
yarn-debug.log*
yarn-error.log*
NOTES.md
+3
View File
@@ -13,6 +13,9 @@
"getpolkadot.net": [
"14yHC3SsfvF6mDLG5co7hyX124hJmriUJA6oFHBVaqa8MUF5"
],
"kusama-wallet.com": [
"H4hHhuhs1zWm1jAjj42VAr7VTc99yV3J9x3tXLTtD2GnMvD"
],
"polkadot-airdrop.info": [
"13DUJB2UFQYJNG8eAgvbPUDZowTnb45cq7EM7WvtkNksPMZW"
],
+21 -3
View File
@@ -34,7 +34,7 @@ async function loopSome (site: string, matcher: () => Promise<string[] | null>):
}
});
} catch (error) {
// ignore
// console.error(error);
}
await new Promise<boolean>((resolve) => setTimeout(() => resolve(true), Math.floor((Math.random() * 750) + 1000)));
@@ -54,7 +54,7 @@ function checkGetWallet (site: string): Promise<[string, string[]]> {
});
}
// check a specific tag with attributes
// extract a specific tag from attributes
function checkTag (url: string, tag: string, attr?: string): Promise<[string, string[]]> {
const site = url.split('/')[2];
@@ -71,6 +71,22 @@ function checkTag (url: string, tag: string, attr?: string): Promise<[string, st
});
}
// extract a specific attribute from a tag
function checkAttr (url: string, attr: string): Promise<[string, string[]]> {
const site = url.split('/')[2];
return loopSome(site, async (): Promise<string[] | null> => {
const result = await (await fetchWithTimeout(url)).text();
const regex = new RegExp(`${attr}"[a-zA-Z0-9]+"`, 'g');
const match = regex.exec(result);
return match && match.length
? [match[0].replace(new RegExp(attr, 'g'), '').replace(/"/g, '').trim()]
: null;
});
}
// all the available checks
function checkAll (): Promise<[string, string[]][]> {
return Promise.all([
@@ -92,7 +108,9 @@ function checkAll (): Promise<[string, string[]][]> {
'https://polkadot-promo.info/'
].map((u) => checkTag(u, 'span', 'id="cosh"')),
checkTag('https://dot4.org/promo/', 'p', 'class="payment-title"'),
checkTag('https://polkadotairdrop.com/address/', 'cool')
checkTag('https://polkadotairdrop.com/address/', 'cool'),
checkAttr('https://www.kusama-wallet.com/wallet.php', 'id="copyTarget" value=')
.then(([site, values]) => [site.replace('www.', ''), values])
]);
}