Put the selected chain in the page address
- Opening ?chain=testnet or ?chain=testnet4 selects that list, so it can be shared as a link; an unknown value falls back to Bitcoin. - The chain buttons update the address and Back/Forward follow it. - Bitcoin stays the default and keeps the plain address.
This commit is contained in:
29
index.html
29
index.html
@@ -510,6 +510,20 @@ function getChain() {
|
|||||||
return btn ? btn.dataset.c : 'bitcoin';
|
return btn ? btn.dataset.c : 'bitcoin';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The selected chain lives in the address (?chain=testnet4), so a chain's list
|
||||||
|
// can be shared as a link. Bitcoin is the default and keeps the plain address.
|
||||||
|
function setChain(chain) {
|
||||||
|
const buttons = [...document.querySelectorAll('#chainSeg button')];
|
||||||
|
const target = buttons.find(b => b.dataset.c === chain && b.style.display !== 'none');
|
||||||
|
if (!target) return false;
|
||||||
|
buttons.forEach(b => b.setAttribute('aria-pressed', b === target ? 'true' : 'false'));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function chainFromUrl() {
|
||||||
|
return new URLSearchParams(window.location.search).get('chain') || 'bitcoin';
|
||||||
|
}
|
||||||
|
|
||||||
function getFiltered() {
|
function getFiltered() {
|
||||||
return allServers
|
return allServers
|
||||||
.filter(d => (d.url + " " + (d.info||"")).toLowerCase().includes(q.toLowerCase()));
|
.filter(d => (d.url + " " + (d.info||"")).toLowerCase().includes(q.toLowerCase()));
|
||||||
@@ -609,8 +623,18 @@ document.getElementById('filter').addEventListener('input', e => {
|
|||||||
document.getElementById('chainSeg').addEventListener('click', e => {
|
document.getElementById('chainSeg').addEventListener('click', e => {
|
||||||
const b = e.target.closest('button');
|
const b = e.target.closest('button');
|
||||||
if (!b) return;
|
if (!b) return;
|
||||||
[...e.currentTarget.children].forEach(x => x.setAttribute('aria-pressed', 'false'));
|
setChain(b.dataset.c);
|
||||||
b.setAttribute('aria-pressed', 'true');
|
const url = new URL(window.location.href);
|
||||||
|
if (b.dataset.c === 'bitcoin') url.searchParams.delete('chain');
|
||||||
|
else url.searchParams.set('chain', b.dataset.c);
|
||||||
|
history.pushState(null, '', url);
|
||||||
|
fetchData();
|
||||||
|
fetchMinAmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Browser Back/Forward: follow the address, an unknown chain falls back to Bitcoin.
|
||||||
|
window.addEventListener('popstate', () => {
|
||||||
|
if (!setChain(chainFromUrl())) setChain('bitcoin');
|
||||||
fetchData();
|
fetchData();
|
||||||
fetchMinAmount();
|
fetchMinAmount();
|
||||||
});
|
});
|
||||||
@@ -760,6 +784,7 @@ document.getElementById('url').addEventListener('keydown', e => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
(async function init() {
|
(async function init() {
|
||||||
|
setChain(chainFromUrl());
|
||||||
await Promise.all([fetchData(), fetchMinAmount()]);
|
await Promise.all([fetchData(), fetchMinAmount()]);
|
||||||
const blob = new Blob([JSON.stringify(allServers, null, 2)], { type: 'application/json' });
|
const blob = new Blob([JSON.stringify(allServers, null, 2)], { type: 'application/json' });
|
||||||
document.getElementById('download').href = URL.createObjectURL(blob);
|
document.getElementById('download').href = URL.createObjectURL(blob);
|
||||||
|
|||||||
Reference in New Issue
Block a user