init
This commit is contained in:
281
index.html
Normal file
281
index.html
Normal file
@@ -0,0 +1,281 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Bal Server List</title>
|
||||
<link rel="icon" href="Logo_nero.ico" type="image/x-icon">
|
||||
<script src="qrcode.min.js"></script>
|
||||
<script src="purify.min.js"></script>
|
||||
<script src="bal.js"></script>
|
||||
<style>
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
margin-top: 20px;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
tr:nth-child(even) {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
body>div:first-of-type{
|
||||
text-align:center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<a href="/"><img alt="BAL LOGO" src="/Logo_nero.png"></a>
|
||||
<h1>Bal Server List</h1>
|
||||
<div>
|
||||
<select id="chain" name="chain">
|
||||
<option selected value="bitcoin">Bitcoin</option>
|
||||
<option value="testnet">Testnet</option>
|
||||
<option>Regtest</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="onion">Include tor: </label><input type="checkbox" name="onion" id="onion" value="yes" checked>
|
||||
</div>
|
||||
<div>
|
||||
<a href="" id="download">Download</a>
|
||||
</div>
|
||||
<table id="willexecutors">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Url</th>
|
||||
<th>Info</th>
|
||||
<th>Fees</th>
|
||||
<th>Version</th>
|
||||
<th>Balance</th>
|
||||
<th>Status</th>
|
||||
<th>Height</th>
|
||||
<th>Wins</th>
|
||||
<th>Score</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><!-- --></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<form id="myServer">
|
||||
<input type="text" id="url" name="url" required placeholder="https://bitcoin-after.life:9137">
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
<div id="result_text"></div>
|
||||
<div>
|
||||
<a id="aqr">
|
||||
<div id="qrcode"></div>
|
||||
</a>
|
||||
</div>
|
||||
<p>Please make sure your server is online before you try to add it</p>
|
||||
<p>Server not online will be removed from this list</p>
|
||||
|
||||
<script>
|
||||
class BalServerList {
|
||||
constructor() {
|
||||
this.chain = 'bitcoin';
|
||||
this.page = 0;
|
||||
this.limit = 100;
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.parseUrlParams();
|
||||
this.bindEvents();
|
||||
this.fetchDataAndPopulateTable();
|
||||
}
|
||||
|
||||
parseUrlParams() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
this.page = parseInt(urlParams.get('page')) || 0;
|
||||
this.limit = parseInt(urlParams.get('limit')) || 100;
|
||||
this.chain = urlParams.get('chain') || 'bitcoin';
|
||||
|
||||
const chainSelect = document.getElementById('chain');
|
||||
chainSelect.value = this.chain;
|
||||
}
|
||||
|
||||
bindEvents() {
|
||||
document.getElementById('onion').addEventListener('change', () => {
|
||||
this.fetchDataAndPopulateTable();
|
||||
});
|
||||
|
||||
document.getElementById('chain').addEventListener('change', (e) => {
|
||||
this.chain = this.getChain();
|
||||
this.fetchDataAndPopulateTable();
|
||||
});
|
||||
|
||||
document.getElementById('myServer').addEventListener('submit', (e) => {
|
||||
this.handleServerSubmission(e);
|
||||
});
|
||||
}
|
||||
|
||||
async handleServerSubmission(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const urlInput = document.getElementById('url');
|
||||
let url = urlInput.value.trim();
|
||||
|
||||
if (!url) return;
|
||||
|
||||
url = this.formatUrl(url);
|
||||
urlInput.value = url;
|
||||
|
||||
try {
|
||||
const response = await fetch('/data', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url, chain: this.chain })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
this.showError(result);
|
||||
} else {
|
||||
this.showSuccess(result, url);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Submission error:', error);
|
||||
this.showError('Network error. Please try again.');
|
||||
}
|
||||
}
|
||||
|
||||
formatUrl(url) {
|
||||
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
||||
return 'https://' + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
showError(message) {
|
||||
const resultDiv = document.getElementById('result_text');
|
||||
resultDiv.innerHTML = `<p style="color:red">${DOMPurify.sanitize(message)}</p>`;
|
||||
}
|
||||
|
||||
showSuccess(result, url) {
|
||||
const invoiceuri = `bitcoin:${result.address}?label=BAL&message=Order+For+url+%26+${encodeURIComponent(result.url)}`;
|
||||
|
||||
const cleanHtml = DOMPurify.sanitize(`
|
||||
<p style="color:green">${url} successfully added</p>
|
||||
<div>
|
||||
Please Pay this invoice to complete the process:<br/>
|
||||
<b><u>Less than ${result.min_amount} sats are considered donations! if you want your server to be listed you have to send at least ${result.min_amount} sats</u></b><br/>
|
||||
<b>Chain:</b> ${result.chain}<br/>
|
||||
<b>Address:</b> ${result.address}<br/>
|
||||
<b>Balance:</b> ${result.balance}<br/>
|
||||
<b>Status:</b> ${result.status}<br/>
|
||||
</div>
|
||||
`);
|
||||
|
||||
document.getElementById("result_text").innerHTML = cleanHtml;
|
||||
|
||||
// Generate QR code
|
||||
const qrElement = document.getElementById("qrcode");
|
||||
qrElement.innerHTML = "";
|
||||
new QRCode(qrElement, invoiceuri);
|
||||
document.getElementById("aqr").href = invoiceuri;
|
||||
}
|
||||
|
||||
getChain() {
|
||||
const select = document.getElementById('chain');
|
||||
return select.value;
|
||||
}
|
||||
|
||||
async fetchDataAndPopulateTable() {
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
page: this.page,
|
||||
limit: this.limit
|
||||
});
|
||||
|
||||
if (!document.getElementById("onion").checked) {
|
||||
params.append("onion", "no");
|
||||
}
|
||||
|
||||
const response = await fetch(`/data/${this.chain}?${params.toString()}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
this.downloadLink(data);
|
||||
this.populateTable(data);
|
||||
} catch (error) {
|
||||
console.error('Error fetching data:', error);
|
||||
this.showTableError();
|
||||
}
|
||||
}
|
||||
|
||||
showTableError() {
|
||||
const tableBody = document.querySelector('#willexecutors tbody');
|
||||
tableBody.innerHTML = '<tr><td colspan="6">Error loading data. Please try again later.</td></tr>';
|
||||
}
|
||||
|
||||
downloadLink(data) {
|
||||
const jsonString = JSON.stringify(data);
|
||||
const blob = new Blob([jsonString], { type: 'application/json;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const downloadLink = document.getElementById('download');
|
||||
downloadLink.href = url;
|
||||
downloadLink.setAttribute('download', 'willexecutors.json');
|
||||
}
|
||||
get_url(id,url){
|
||||
|
||||
}
|
||||
populateTable(willexecutors) {
|
||||
const tableBody = document.querySelector('#willexecutors tbody');
|
||||
tableBody.innerHTML = '';
|
||||
|
||||
if (Object.keys(willexecutors).length === 0) {
|
||||
tableBody.innerHTML = '<tr><td colspan="9">No servers found</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
Object.entries(willexecutors).forEach(([key, we]) => {
|
||||
const row = document.createElement('tr');
|
||||
|
||||
this.appendRawTd(`<a href='/weinfo/${we.chain}/${we.id}'>${we.url}</a>`, row);
|
||||
this.appendTd(we.info || ' ', row);
|
||||
this.appendTd(we.base_fee, row);
|
||||
this.appendTd(we.version, row);
|
||||
this.appendTd(we.balance, row);
|
||||
this.appendTd(we.status, row);
|
||||
this.appendTd(we.last_block, row);
|
||||
this.appendTd(we.count_win, row);
|
||||
this.appendTd(we.points, row);
|
||||
tableBody.appendChild(row);
|
||||
});
|
||||
}
|
||||
|
||||
appendTd(content, tr) {
|
||||
const td = document.createElement('td');
|
||||
td.textContent = content;
|
||||
tr.appendChild(td);
|
||||
}
|
||||
appendRawTd(content,tr){
|
||||
const td = document.createElement('td');
|
||||
td.innerHTML = DOMPurify.sanitize(content);
|
||||
tr.appendChild(td);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
new BalServerList();
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user