Retrieve new meta structure (#776)

* Retrieve new meta structure

* Adjust

* Var declaration
This commit is contained in:
Jaco
2021-12-06 09:45:35 +01:00
committed by GitHub
parent a9998a8c22
commit c7e4e0d7d5
2 changed files with 44 additions and 7486 deletions
+44 -28
View File
@@ -89,7 +89,7 @@
let hue = Math.floor(Math.random() * 359); let hue = Math.floor(Math.random() * 359);
let counter = 0; let counter = 0;
let navTo = ''; let navTo = '';
let metaJson; let metaJson = [];
let addrJson; let addrJson;
let urlStatus; let urlStatus;
let balances = []; let balances = [];
@@ -191,38 +191,42 @@
}); });
} }
function fillSites () { function fillSites (items = metaJson) {
let prevMonth = ''; if (navTo === 'sites') {
let countIndex = -1; let prevMonth = '';
const count = metaJson.reduce((count, { date }) => { let countIndex = -1;
const thisMonth = date.split('-').slice(0, 2).join('-'); const count = items.reduce((count, { date }) => {
const thisMonth = date.split('-').slice(0, 2).join('-');
if (thisMonth !== prevMonth) { if (thisMonth !== prevMonth) {
count.push(0); count.push(0);
prevMonth = thisMonth; prevMonth = thisMonth;
} }
count[count.length - 1] += 1; count[count.length - 1] += 1;
return count; return count;
}, []); }, []);
prevMonth = ''; prevMonth = '';
metaJson.forEach(({ date, url }, index) => { items.forEach(({ date, url }, index) => {
const thisMonth = date.split('-').slice(0, 2).join('-'); const thisMonth = date.split('-').slice(0, 2).join('-');
if (thisMonth !== prevMonth) { if (thisMonth !== prevMonth) {
const c = document.createElement('h3'); const c = document.createElement('h3');
countIndex++; countIndex++;
c.appendChild(document.createTextNode(`${thisMonth} (${count[countIndex]})`)); c.appendChild(document.createTextNode(`${thisMonth} (${count[countIndex]})`));
appendHeader(c); appendHeader(c);
prevMonth = thisMonth; prevMonth = thisMonth;
} }
appendRow(date, url, urlStatus[index] ? 'active' : 'inactive'); appendRow(date, url, urlStatus[index] ? 'active' : 'inactive');
}); });
}
document.getElementById('btn-sites').innerText = `Sites (${metaJson.length})`;
} }
function fillTable (newNav) { function fillTable (newNav) {
@@ -291,9 +295,10 @@
draw(); draw();
const from = window.location.protocol === 'file:' ? 'https://polkadot.js.org/phishing/' : ''; const from = window.location.protocol === 'file:' ? 'https://polkadot.js.org/phishing/' : '';
const [addrBody, metaBody] = await Promise.all(['address', 'urlmeta'].map((j) => fetchTimeout(`${from}${j}.json`))); const [addrBody, metaBody] = await Promise.all(['address', 'meta/index'].map((j) => fetchTimeout(`${from}${j}.json`)));
let metaMonths;
[addrJson, metaJson] = await Promise.all([addrBody.json(), metaBody.json()]); [addrJson, metaMonths] = await Promise.all([addrBody.json(), metaBody.json()]);
const addresses = Object const addresses = Object
.values(addrJson) .values(addrJson)
@@ -311,11 +316,22 @@
search.addEventListener('input', onSearch); search.addEventListener('input', onSearch);
search.style.display = 'block'; search.style.display = 'block';
document.getElementById('btn-sites').innerText = `Sites (${metaJson.length})`;
document.getElementById('btn-addresses').innerText = `Addresses (${Object.values(addrJson).reduce((count, addrs) => count + addrs.length, 0)})`; document.getElementById('btn-addresses').innerText = `Addresses (${Object.values(addrJson).reduce((count, addrs) => count + addrs.length, 0)})`;
document.getElementById('btn-sites').innerText = `Sites (0)`;
document.getElementById('buttons').style.display = 'block'; document.getElementById('buttons').style.display = 'block';
fillTable('sites'); fillTable('sites');
for (const month of metaMonths) {
const response = await fetchTimeout(`${from}meta/${month}.json`);
const items = await response.json();
for (const item of items) {
metaJson.push(item);
}
fillSites(items);
}
} }
main(); main();
-7458
View File
File diff suppressed because it is too large Load Diff