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 counter = 0;
let navTo = '';
let metaJson;
let metaJson = [];
let addrJson;
let urlStatus;
let balances = [];
@@ -191,38 +191,42 @@
});
}
function fillSites () {
let prevMonth = '';
let countIndex = -1;
const count = metaJson.reduce((count, { date }) => {
const thisMonth = date.split('-').slice(0, 2).join('-');
function fillSites (items = metaJson) {
if (navTo === 'sites') {
let prevMonth = '';
let countIndex = -1;
const count = items.reduce((count, { date }) => {
const thisMonth = date.split('-').slice(0, 2).join('-');
if (thisMonth !== prevMonth) {
count.push(0);
prevMonth = thisMonth;
}
if (thisMonth !== prevMonth) {
count.push(0);
prevMonth = thisMonth;
}
count[count.length - 1] += 1;
count[count.length - 1] += 1;
return count;
}, []);
return count;
}, []);
prevMonth = '';
prevMonth = '';
metaJson.forEach(({ date, url }, index) => {
const thisMonth = date.split('-').slice(0, 2).join('-');
items.forEach(({ date, url }, index) => {
const thisMonth = date.split('-').slice(0, 2).join('-');
if (thisMonth !== prevMonth) {
const c = document.createElement('h3');
if (thisMonth !== prevMonth) {
const c = document.createElement('h3');
countIndex++;
c.appendChild(document.createTextNode(`${thisMonth} (${count[countIndex]})`));
appendHeader(c);
prevMonth = thisMonth;
}
countIndex++;
c.appendChild(document.createTextNode(`${thisMonth} (${count[countIndex]})`));
appendHeader(c);
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) {
@@ -291,9 +295,10 @@
draw();
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
.values(addrJson)
@@ -311,11 +316,22 @@
search.addEventListener('input', onSearch);
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-sites').innerText = `Sites (0)`;
document.getElementById('buttons').style.display = 'block';
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();
-7458
View File
File diff suppressed because it is too large Load Diff