Skip to content

Commit

Permalink
Add /coin/ETH pages (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrLuit authored Sep 30, 2018
1 parent 9086048 commit c5bae20
Show file tree
Hide file tree
Showing 3 changed files with 281 additions and 2 deletions.
81 changes: 79 additions & 2 deletions src/utils/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,85 @@ router.get('/scams/:page?/:sorting?/', (req, res) => {
}
});

/* Search pages */
router.get('/search/', (req, res) => res.render('search', { featured: db.read().index.featured }));
/* Coin pages */
router.get('/coin/:coin/:page?/:sorting?/', (req, res) => {
const MAX_RESULTS_PER_PAGE = 30;
const scamList = [];
let scams = [...db.read().scams.filter(scam => scam.coin === req.params.coin)].reverse();
let index = [0, MAX_RESULTS_PER_PAGE];

if (
req.params.page &&
req.params.page !== 'all' &&
(!isFinite(parseInt(req.params.page, 10)) ||
isNaN(parseInt(req.params.page, 10)) ||
parseInt(req.params.page, 10) < 1)
) {
res.status(404).render('404');
} else {
if (req.params.sorting === 'oldest') {
scams = db.read().scams.filter(scam => scam.coin === req.params.coin);
} else if (req.params.sorting === 'status') {
scams = [...db.read().scams.filter(scam => scam.coin === req.params.coin)].sort(
(a, b) => (a.status || '').localeCompare(b.status || '')
);
} else if (req.params.sorting === 'category') {
scams = [...db.read().scams.filter(scam => scam.coin === req.params.coin)].sort(
(a, b) => (a.category || '').localeCompare(b.category || '')
);
} else if (req.params.sorting === 'subcategory') {
scams = [...db.read().scams.filter(scam => scam.coin === req.params.coin)].sort(
(a, b) => (a.subcategory || '').localeCompare(b.subcategory || '')
);
} else if (req.params.sorting === 'name') {
scams = [...db.read().scams.filter(scam => scam.coin === req.params.coin)].sort(
(a, b) => a.getHostname().localeCompare(b.getHostname())
);
}

if (req.params.page === 'all') {
index = [0, scams.length - 1];
} else if (req.params.page) {
index = [
(req.params.page - 1) * MAX_RESULTS_PER_PAGE,
req.params.page * MAX_RESULTS_PER_PAGE
];
}

for (let i = index[0]; i <= index[1]; i++) {
if (scams.hasOwnProperty(i) === false) {
continue;
}
scamList.push(scams[i]);
}

res.render('coin', {
coin: req.params.coin,
page: req.params.page,
sorting: req.params.sorting,
total: scams.length.toLocaleString('en-US'),
active: Object.keys(
scams.filter(scam => scam.status === 'Active')
).length.toLocaleString('en-US'),
total_addresses: Object.keys(db.read().index.addresses)
.filter(address =>
db.read().index.addresses[address].some(scam => scam.coin === req.params.coin)
)
.length.toLocaleString('en-US'),
inactive: Object.keys(
scams.filter(scam => scam.status === 'Inactive')
).length.toLocaleString('en-US'),
scams: scamList,
MAX_RESULTS_PER_PAGE,
scamsLength: scams.length
});
}
});

/* Verified pages */
router.get('/verified/', (req, res) =>
res.render('verified', { featured: db.read().index.featured })
);

/* RSS */
router.get('/rss/', (req, res) => res.render('rss', { scams: db.read().scams }));
Expand Down
188 changes: 188 additions & 0 deletions src/views/pages/coin.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<!DOCTYPE html>
<html lang="en">

<head>
<% include ../partials/header %>
<link rel="stylesheet" href="/css/scams.css">
</head>

<body>
<% include ../partials/navbar %>
<div class="ui body container">
<div class="ui grid">
<div class="four wide column">
<div class="ui tiny statistic">
<div class="value">
<%= total %>
</div>
<div class="label">
Total scams
</div>
</div>
</div>
<div class="four wide column">
<div class="ui tiny statistic">
<div class="value">
<%= active %>
</div>
<div class="label">
Active scams
</div>
</div>
</div>
<div class="four wide column">
<div class="ui tiny statistic">
<div class="value">
<%= total_addresses %>
</div>
<div class="label">
Addresses registered
</div>
</div>
</div>
<div class="four wide column">
<div class="ui tiny statistic">
<div class="value">
<%= inactive %>
</div>
<div class="label">
Inactive scams
</div>
</div>
</div>
</div>
<h1 class="scams"><i class="protect icon"></i> Scams</h1>
<table class="ui sortable celled table">
<thead>
<tr>
<% if(sorting == "category") { %>
<th class="sorted descending">Category</th>
<% } else { %>
<th>Category</th>
<% } %>
<% if(sorting == "subcategory") { %>
<th class="sorted descending">Subcategory</th>
<% } else { %>
<th>Subcategory</th>
<% } %>
<% if(sorting == "status") { %>
<th class="sorted descending">Status</th>
<% } else { %>
<th>Status</th>
<% } %>
<% if(sorting == "name") { %>
<th class="sorted descending">Name</th>
<% } else { %>
<th>Name</th>
<% } %>
<th id='info'>Info</th>
</tr></thead>
<tbody>
<% scams.forEach(scam => { %>
<tr>
<% if("category" in scam && scam.category) { %>
<% if(scam.category == "Phishing") { %>
<td><i class="address book icon"></i> Phishing</td>
<% } else if(scam.category == "Scamming") { %>
<td><i class="address book icon"></i> Scamming</td>
<% } else if(scam.category == "Fake ICO") { %>
<td><i class="address book icon"></i> Fake ICO</td>
<% } else { %>
<td><i class="address book icon"></i> <%= scam.category %></td>
<% } %>
<% } else { %>
<td><i class="remove icon"></i> None</td>
<% } %>
<% if("subcategory" in scam && scam.subcategory) { %>
<% if(scam.subcategory == "Wallets") { %>
<td><i class="credit card alternative icon"></i> Wallets</td>
<% } else if(scam.subcategory == "Trust-Trading") { %>
<td><i class="handshake outline icon"></i> Trust-Trading</td>
<% } else { %>
<td><img src='/assets/<%= scam.subcategory.toLowerCase().replace(/\s/g, "") %>.png' class='subcategoryicon' onerror="this.style.display='none'"> <%= scam.subcategory %></td>
<% } %>
<% } else { %>
<td><i class="remove icon"></i> None</td>
<% } %>
<% if("status" in scam && scam.status) { %>
<% if(scam.status == "Active") { %>
<td class='offline'><i class='warning sign icon'></i> Active</td>
<% } else if(scam.status == "Inactive") { %>
<td class='suspended'><i class='remove icon'></i> Inactive</td>
<% } else if(scam.status == "Suspended") { %>
<td class='suspended'><i class='remove icon'></i> Suspended</td>
<% } else if(scam.status == "Offline") { %>
<td class='activ'><i class='checkmark icon'></i> Offline</td>
<% } %>
<% } else { %>
<td>Unknown</td>
<% } %>
<% if(scam.getHostname().length > 40) { %>
<td><%= scam.getHostname().substring(0, 40) %>...</td>
<% } else { %>
<td><%= scam.getHostname() %></td>
<% } %>
<td class='center'>
<a href='/domain/<%= scam.getHostname() %>'><i class='search icon'></i></a>
</td>
</tr>
<% }); %>
</tbody>
</table>
<% if(page !== "all") { %>
<div class="ui pagination menu">
<%
let strPagination = "";
let intCurrentPage = parseInt(page || 0);
let arrLoop = [-2, 3];
if (intCurrentPage == 0) arrLoop = [1, 6];
else if (intCurrentPage == 1) arrLoop = [0, 5];
else if (intCurrentPage == 2) arrLoop = [-1, 4];
for (var i = arrLoop[0]; i < arrLoop[1]; i++) {
var intPageNumber = intCurrentPage+i;
var strItemClass = "item";
var strHref = "/coin/" + coin + "/" + intPageNumber + "/";
if (sorting) strHref += sorting + "/";
if ((intPageNumber > (scamsLength) / MAX_RESULTS_PER_PAGE) || (intPageNumber < 1)) {
strItemClass = "disabled item";
strHref = "#";
} else if (intCurrentPage == intPageNumber) {
strItemClass = "active item";
}
strPagination += "<a href='" + strHref + "' class='" + strItemClass + "'>" + intPageNumber + "</a>";
}
if (intCurrentPage > 3) {
if (sorting) {
strPagination = "<a class='item' href='/coin/" + coin + "/1/" + sorting + "'><i class='angle double left icon'></i></a>" + strPagination;
} else {
strPagination = "<a class='item' href='/coin/" + coin + "/1/" + sorting + "'><i class='angle double left icon'></i></a>" + strPagination;
}
}
if (intCurrentPage < Math.ceil(scamsLength / MAX_RESULTS_PER_PAGE) - 3) {
if (sorting) {
strPagination += "<a class='item' href='/coin/" + coin + "/" + (Math.ceil(scamsLength / MAX_RESULTS_PER_PAGE) - 1) + "/" + sorting + "'><i class='angle double right icon'></i></a>";
} else {
strPagination += "<a class='item' href='/coin/" + coin + "/" + (Math.ceil(scamsLength / MAX_RESULTS_PER_PAGE) - 1) + "'><i class='angle double right icon'></i></a>";
}
}
%>
<%- strPagination %>
</div>
<% } %>
</div>
</div>
<% include ../partials/footer %>
<script>const coin = "<%= coin %>";</script>
<script src="/js/coin.js"></script>
</body>

</html>
14 changes: 14 additions & 0 deletions src/views/static/js/coin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
window.addEventListener("load", function() {
$("th").click(function() {
if($(this).html() !== 'Info') {
$("th").removeClass("sorted descending");
$(this).addClass("sorted descending");
path = window.location.pathname.split("/");
if(!(3 in path) || path[3] === '') {
window.location = "/coin/" + coin + "/1/" + $(this).html().toLowerCase();
} else {
window.location = "/coin/" + coin + "/" + path[3] + "/" + $(this).html().toLowerCase();
}
}
});
});

0 comments on commit c5bae20

Please sign in to comment.