forked from polkadot-js/phishing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
253 lines (206 loc) · 9.29 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=0.5, maximum-scale=1">
<link rel="shortcut icon" href="favicon.ico">
<title>polkadot{.js}/phishing</title>
<style>
:root {
--font-sans: "-apple-system", BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
a { color: #ff8c00 !important; text-decoration: none }
body { color: #4e4e4e; font-family: var(--font-sans); height: 100vh; overflow-x: hidden; padding: 0 }
h3 { font-family: var(--font-sans); font-size: 1em; font-weight: 400; margin: 1rem 0; opacity: 0.95; text-transform: lowercase }
p { line-height: 1.5rem; margin: 0.75rem 0 }
.box { background: rgba(255, 255, 255, 0.85); border-radius: 0.25rem; flex: 1 1; margin: 0.5rem; min-width: 15rem; max-width: 40rem; padding: 0 1.5rem; text-align: center; white-space: nowrap; width: 40rem; z-index: 2 }
.buttons { display: none; margin: 2rem 0 1.5rem }
.buttons a { border: 1px solid #eee; border-radius: 0.25rem; margin: 0 0.25rem; padding: 0.5rem 0.75rem }
.buttons .invert { color: rgba(255, 255, 255, 0.85) !important }
.container { align-items: center; display: flex; flex-direction: column; justify-content: center; margin-top: 4rem; padding-bottom: 2rem }
.desc { font-size: 0.95rem; opacity: 0.85; white-space: normal }
.dot { border-radius: 50%; position: absolute; z-index: 0 }
.header { align-items: center; background: rgba(255, 255, 255, 0.85); display: flex; left: 0; justify-content: space-between; padding: 0.5rem 1rem; position: fixed; right: 0; top: 0; z-index: 1 }
.header div.logo { display: flex; align-items: center }
.header img { height: 1.5rem; margin-right: 0.5rem; width: 1.5rem }
.row { align-items: center; display: flex; justify-content: center }
table { margin: 0 0 1rem }
td:not(.centered) { font-family: monospace; padding: 0.25rem 0.5rem; text-align: right }
td.centered { opacity: 0.65; padding: 1rem; text-align: center }
td:nth-child(2) { width: 100% }
td > h3 { margin: 0; opacity: 0.25 }
tr + tr > td > h3 { margin-top: 0.5rem }
td > span { border-radius: 0.25em; color: white; font-size: 0.75rem; padding: 0.125em 0.375em }
td > span.active { background: darkred }
td > span.inactive { background: darkgrey; display: none }
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="box">
<h3>phishing</h3>
<p class="desc">A community driven curated list of known less-than-honest operators.</p>
<p class="desc">Any additions can be made by editing <a href="https://github.com/polkadot-js/phishing/edit/master/all.json">phishing/all.json</a> and adding any new sites in alphabetical order. In the same vein addresses can be added in <a href="https://github.com/polkadot-js/phishing/edit/master/address.json">phishing/address.json</a>. For any discrepancies or requests <a href="https://github.com/polkadot-js/phishing/issues">log an issue</a>.</p>
<p id="buttons" class="buttons"><a href="#" id="btn-sites" onclick="fillTable('sites')">Sites</a><a href="#" id="btn-addresses" onclick="fillTable('addresses')">Addresses</a></p>
<table>
<tbody id="table">
<tr>
<td></td>
<td class="centered">.. loading url & address metadata ...</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="header">
<div class="logo">
<img src="https://polkadot.js.org/logo.svg" />
<div>polkadot{.js}/phishing</div>
</div>
<a href="https://github.com/polkadot-js/phishing">view on github</a>
</div>
<script>
if (window.self !== window.top) {
window.top.location.href = window.location.href;
}
const style = document.createElement('style');
const table = document.getElementById('table');
document.head.appendChild(style);
let hue = Math.floor(Math.random() * 359);
let counter = 0;
let navTo = '';
let metaJson;
let addrJson;
let urlStatus;
let balances = [];
function draw () {
hue = (hue + 1) % 360;
document.body.style.background = `hsl(${hue}, 45%, 85%)`;
style.innerHTML = `a { color: hsl(${hue}, 45%, 45%) !important } .buttons a { border-color: hsl(${hue}, 45%, 45%) !important } .buttons .invert { background: hsl(${hue}, 45%, 45%) !important }`;
setTimeout(() => window.requestAnimationFrame(draw), 100);
}
function appendRow (date, url = '', status) {
const row = document.createElement('tr');
const a = document.createElement('td');
const b = document.createElement('td');
const c = document.createElement('td');
a.appendChild(document.createTextNode(url));
if (typeof date === 'string') {
b.appendChild(document.createTextNode(date));
} else {
b.appendChild(date);
}
if (typeof status === 'string') {
const s = document.createElement('span');
s.classList.add(status);
s.appendChild(document.createTextNode(status));
c.appendChild(s);
}
row.appendChild(a);
row.appendChild(b);
row.appendChild(c);
table.appendChild(row);
}
function fillAddressList (url, addresses) {
if (addresses && addresses.length) {
const c = document.createElement('h3');
c.appendChild(document.createTextNode(url));
appendRow(c);
addresses.forEach((address) => {
const balance = balances.find(([a]) => a === address) || ['', '']
appendRow(balance[1], address);
});
}
}
function fillAddresses () {
metaJson.forEach(({ url }) => fillAddressList(url, addrJson[url]));
Object.entries(addrJson).forEach(([url, addresses]) => {
if (!metaJson.find((m) => m.url === url)) {
fillAddressList(url, addresses);
}
});
}
function fillSites () {
let prevMonth = '';
metaJson.forEach(({ date, url }, index) => {
const thisMonth = date.split('-').slice(0, 2).join('-');
if (thisMonth !== prevMonth) {
const c = document.createElement('h3');
c.appendChild(document.createTextNode(thisMonth));
appendRow(c);
prevMonth = thisMonth;
}
appendRow(date, url, urlStatus[index] ? 'active' : 'inactive');
});
}
function fillTable (newNav) {
if (newNav !== navTo) {
if (navTo) {
document.getElementById(`btn-${navTo}`).classList = '';
}
document.getElementById(`btn-${newNav}`).classList = 'invert';
navTo = newNav;
table.innerHTML = '';
if (navTo === 'sites') {
fillSites();
} else {
fillAddresses();
}
}
}
async function fetchTimeout (url, options = {}) {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), 2500);
const response = await fetch(url, { ...options, signal: controller.signal });
clearTimeout(id);
return response;
}
async function isUp (url) {
try {
await fetchTimeout(url, { method: 'HEAD', mode: 'no-cors' });
const response = await fetchTimeout(`https://proxy.dotapps.workers.dev/?${url}`, { follow: 'error' });
return response.status === 200;
} catch (error) {
return false;
}
}
async function getBalance (key) {
try {
const response = await fetchTimeout('https://polkadot.subscan.io/api/scan/search', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key, page: 0, row: 1 })
});
const { data } = await response.json();
const [pre, post] = ((data && data.account.balance) || '0').split('.');
return [key, `${pre}.${`${post || ''}0000000000`.substr(0, 10)}`];
} catch (error) {
console.error(error);
return [key, ''];
}
}
async function main () {
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`)));
[addrJson, metaJson] = await Promise.all([addrBody.json(), metaBody.json()]);
const addresses = Object
.values(addrJson)
.reduce((all, addrs) => {
addrs.forEach((a) => !all.includes(a) && all.push(a));
return all;
}, []);
[balances, urlStatus] = await Promise.all([
Promise.all(addresses.map(getBalance)),
Promise.all(metaJson.map(({ url }) => isUp(`https://${url}`)))
]);
document.getElementById('buttons').style.display = 'block';
fillTable('sites');
}
main();
</script>
</body>
</html>